The Easiest Way to Save and Share Code Snippets on the web

Concept Enforcing

cpp

posted: Apr, 15th 2011 | jump to bottom

 
#include <string>
#include <iostream>
 
struct Interface
{
	void Output(const std::string Text) const;
};
 
struct ValidClass: public Interface
{
	void Output(const std::string Text) const
	{
		std::cout << Text << std::endl;
	}
};
 
struct InvalidClass: public Interface
{
};
 
template <typename Datatype>
void SayHello(const Datatype Object)
{
	Object.Output("Hello, world!");
};
 
int main()
{
	ValidClass Valid;
	InvalidClass Invalid;
 
	SayHello(Valid);
	SayHello(Invalid);
 
	return 0;
}
9 views