Not sure if I fully understand the question because you have work.
class X
{
public:
void my_method() { std::cout << "I'm X"; }
};
class Z
{
};
template <typename T>
class Y
{
public:
void put(T item) { item.my_method(); }
};
int main(int argc, char* argv[])
{
X theX;
Y<X> theXY;
theXY.put( theX );
Z theZ;
Y<Z> theYZ;
theYZ.put( theZ );
}
When Y is used with a class that does not have a member my_method(), it does not compile.
source
share