How to tell if class contains a certain member function in compile time [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is it possible to write a C++ template to check for a function's existence? say there are 2 classes: struct A{ int GetInt(){ return 10; } }; struct B{ int m; }; I want to use object of type A or B in following function tempate< typename T > int GetInt( const T & t ) { //if it's A, I'll call: return t.GetInt(); //if its' B, I'll call: return t.m; } Now, because there are whole bunch of classes, some contain