Не уверен, что я полностью понимаю вопрос, потому что у вас работает.
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[])
{
// This compiles fine
X theX;
Y<X> theXY;
theXY.put( theX );
// ERROR: This fails to compile
Z theZ;
Y<Z> theYZ;
theYZ.put( theZ );
}
Когда Y используется с классом, который не имеет члена my_method()
, он не может скомпилироваться.