1、tinybind.h there are no arguments to `params' that depend on a template parameter, so a declaration of `params' must be available。。。
solution:参考一下文档
11.9.2. Name lookup, templates, and accessing members of base classes
The C++ standard prescribes that all names that are not dependent ontemplate parameters are bound to their present definitions when parsinga template function or class.[1] Only names that are dependent are looked up at the pointof instantiation. For example, consider
void foo(double); struct A { template <typename T> void f () { foo (1); // 1 int i = N; // 2 T t; t.bar(); // 3 foo (t); // 4 } static const int N; }; |
Here, the names foo and N appear in a context that doesnot depend on the type ofT. The compiler will thus require thatthey are defined in the context of use in the template, not only beforethe point of instantiation, and will here use::foo(double) andA::N, respectively. In particular, it will convert the integervalue to adouble when passing it to ::foo(double).
Conversely, bar and the call to foo in the fourth markedline are used in contexts that do depend on the type ofT, sothey are only looked up at the point of instantiation, and you canprovide declarations for them after declaring the template, but beforeinstantiating it. In particular, if you instantiateA::f<int>,the last line will call an overloaded ::foo(int) if one wasprovided, even if after the declaration of struct A.
This distinction between lookup of dependent and non-dependent names iscalled two-stage (or dependent) name lookup. G++ implements itsince version 3.4.
Two-stage name lookup sometimes leads to situations with behaviordifferent from non-template codes. The most common is probably this:
template <typename T> struct Base { int i; }; template <typename T> struct Derived : public Base<T> { int get_i() { return i; } }; |
In get_i(), i is not used in a dependent context, so thecompiler will look for a name declared at the enclosing namespace scope(which is the global scope here). It will not look into the base class,since that is dependent and you may declare specializations ofBase even after declaringDerived, so the compiler can'treally know what i would refer to. If there is no globalvariable i, then you will get an error message.
In order to make it clear that you want the member of the base class,you need to defer lookup until instantiation time, at which the baseclass is known. For this, you need to accessi in a dependentcontext, by either using this->i (remember that this is oftype Derived<T>*, so is obviously dependent), or usingBase<T>::i. Alternatively,Base<T>::i might be broughtinto scope by a using-declaration.
Another, similar example involves calling member functions of a baseclass:
template <typename T> struct Base { int f(); }; template <typename T> struct Derived : Base<T> { int g() { return f(); }; }; |
Again, the call to f() is not dependent on template arguments(there are no arguments that depend on the typeT, and it is alsonot otherwise specified that the call should be in a dependent context).Thus a global declaration of such a function must be available, sincethe one in the base class is not visible until instantiation time. Thecompiler will consequently produce the following error message:
x.cc: In member function `int Derived<T>::g()': x.cc:6: error: there are no arguments to `f' that depend on a template parameter, so a declaration of `f' must be available x.cc:6: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated) |
To make the code valid either use this->f(), orBase<T>::f(). Using the-fpermissive flag will also letthe compiler accept the code, by marking all function calls for which nodeclaration is visible at the time of definition of the template forlater lookup at instantiation time, as if it were a dependent call.We do not recommend using -fpermissive to work around invalidcode, and it will also only catch cases where functions in base classesare called, not where variables in base classes are used (as in theexample above).
Note that some compilers (including G++ versions prior to 3.4) get theseexamples wrong and accept above code without an error. Those compilersdo not implement two-stage name lookup correctly.
2、tinybind.cpp template-id `ConvertFromString<const char*>' in declaration of primary template
void
ConvertFromString<char const *>( char const * strIn, const char * * dataOut )
改为
template<>
void
ConvertFromString ( char const * strIn, const char * * dataOut )
类似问题一样改正
3、
error: 'ConvertToString' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
将template<class T>
char const *
ConvertToString( T const & t );
template<class T>
void ConvertFromString( char const * strIn, T * dataOut );
这两个声明放在tinybind.h文件前面(由于该声明放在调用函数之后,故找不着)