c********e 发帖数: 383 | 1 plz compile below code for me if you could, thx.
#include
/*
//normal one works
template
class Base
{
public:
Base (int i) : i_ (i) {}
private:
int i_;
};
template
class Upper : public Base >
{
public:
Upper (int t) : Base > (t) {}
};
int main ()
{
Upper up (1);
}
*/
//template template workes with implicit base mem call
//but can not call explicitly.
template class Derived>
class Base
{
public: |
t****t 发帖数: 6806 | 2 不行
1.C: In constructor 'Upper::Upper(int)':
1.C:46: error: type/value mismatch at argument 1 in template parameter list
for 'template class Derived> class Base'
1.C:46: error: expected a class template, got 'Upper'
【在 c********e 的大作中提到】 : plz compile below code for me if you could, thx. : #include : /* : //normal one works : template : class Base : { : public: : Base (int i) : i_ (i) {} : private:
|
t****t 发帖数: 6806 | 3 原因是这样
14.6.1
1 Within the scope of a class template, when the name of the template is
neither qualified nor followed by <, it is equivalent to the name of
the template followed by the template-parameters enclosed in <>.
[Example: the constructor for Set can be referred to as Set() or
Set(). ] Other specializations (_temp.expl.spec_) of the class can
be referred to by explicitly qualifying the template name with the
appropriate template-arguments. [Example:
te
【在 t****t 的大作中提到】 : 不行 : 1.C: In constructor 'Upper::Upper(int)': : 1.C:46: error: type/value mismatch at argument 1 in template parameter list : for 'template class Derived> class Base' : 1.C:46: error: expected a class template, got 'Upper'
|
c********e 发帖数: 383 | 4 ah...thrust u rule.
but can u post the working code? i dont have access to the newer compiler.
【在 t****t 的大作中提到】 : 原因是这样 : 14.6.1 : 1 Within the scope of a class template, when the name of the template is : neither qualified nor followed by <, it is equivalent to the name of : the template followed by the template-parameters enclosed in <>. : [Example: the constructor for Set can be referred to as Set() or : Set(). ] Other specializations (_temp.expl.spec_) of the class can : be referred to by explicitly qualifying the template name with the : appropriate template-arguments. [Example: : te
|
c********e 发帖数: 383 | 5 nevermind, got it. 3.4 works the same way.
thx
【在 c********e 的大作中提到】 : ah...thrust u rule. : but can u post the working code? i dont have access to the newer compiler.
|
r****t 发帖数: 10904 | 6 thrust 你这个原因是查的什么资料?有时候有些错误看不懂,你这个资料好像很有用。
【在 t****t 的大作中提到】 : 原因是这样 : 14.6.1 : 1 Within the scope of a class template, when the name of the template is : neither qualified nor followed by <, it is equivalent to the name of : the template followed by the template-parameters enclosed in <>. : [Example: the constructor for Set can be referred to as Set() or : Set(). ] Other specializations (_temp.expl.spec_) of the class can : be referred to by explicitly qualifying the template name with the : appropriate template-arguments. [Example: : te
|