
On Mon, Mar 22, 2010 at 9:12 AM, Ingo Loehken <Ingo.Loehken@boc-eu.com> wrote:
below you find the appropiate code, that checks if a set of functions is declared for a type T, where the declaration should be inherited from nsISupports (or any other interface). So you'd can determine, if the function is overloaded or not.
It turned out that I only needed to check if a struct is declared within one of the base classes or not. This seems simpler that my original goal for has_function and I was able to adapt Ingo's code to get the job done -- see below. However, I am getting the following compiler error: $ g++ -Wall -Werror test/noinherit/05.cpp test/noinherit/05.cpp: In instantiation of ‘const bool z::has_contract_f_<x>::value’: test/noinherit/05.cpp:34: instantiated from here test/noinherit/05.cpp:31: error: the default argument for parameter 1 of ‘static char z::has_contract_f_<T>::check(C*, typename C::contract_f_<0>*) [with C = x, T = x]’ has not yet been parsed Do you know how I can get around this error? // File test/noinherit/05.cpp #include <iostream> struct x { virtual void f() {} template<int Z> struct contract_f_ {}; }; struct y { void g() {} template<int Z> struct contract_g_ {}; }; struct z: x, y { void f() {} template<int Z> struct contract_f_ {}; template<typename T> struct has_contract_f_ { private: typedef char true_t; struct false_t { true_t dummy[2]; }; static T* make(); static false_t check(...); template<typename C> static true_t check(C*, typename C::template contract_f_<0>* = 0); public: static const bool value = sizeof(check(make())) == sizeof(true_t); // line 31 }; static const bool bx = has_contract_f_<x>::value; // line 34 static const bool by = has_contract_f_<y>::value; }; int main() { std::cout << z::bx << std::endl; std::cout << z::by << std::endl; return 0; } If has_contract_f_ is declared outside struct z than there is no error -- the code compiles and works. However, I need has_contract_f_ to be a member struct of z, because of the way I use it within my library, and that generates the compiler error reported above. Thanks a lot. Lorenzo