模板语法问题,跟ADL、
c++吧
全部回复
仅看楼主
level 12
v2abcd 楼主
#include <iostream>
template <typename T>
class a
{
public:
func(){std::cout << "func" << std::endl;};
};
template <typename T>
class b : public a<T>
{
public:
b()
{
func();
}
};
int main()
{
b<int> inlb;
return 0;
}
48test.cpp:7:10: error: ISO C++ forbids declaration of ‘func’ with no type [-fpermissive]
48test.cpp: In constructor ‘b<T>::b()’:
48test.cpp:16:14: error: there are no arguments to ‘func’ that depend on a template parameter, so a declaration of ‘func’ must be available [-fpermissive]
48test.cpp:16:14: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
2013年08月16日 07点08分 1
level 12
v2abcd 楼主
手抖没发完
GCC 4.3以前的版本没问题的
4.7有这个规定
如果我需在在b中调用a的func,语法要怎么写呢?试了a<T>::func()不管用...
2013年08月16日 07点08分 2
level 12
v2abcd 楼主
2013年08月16日 09点08分 3
level 15
。。。func返回啥?
2013年08月16日 09点08分 4
[狂汗]这是个问题,还有一个问题
2013年08月16日 09点08分
第二个错误才是我想问的
2013年08月16日 09点08分
回复 v2abcd :调用a<T>::func()不行?
2013年08月16日 19点08分
回复 幻の上帝 :ok
2013年08月17日 00点08分
level 6
改成a<T>::func也不行?我用g++ 4.6.1和g++ 4.8.1都能通过啊?你改成this->func()试试
2013年08月16日 11点08分 5
level 7
怎么我用这个能管用a<T>::func()
2013年08月16日 11点08分 6
1