为什么我无法编译此代码?
#include <map>
using namespace std;
class MyTest {
template<typename T> void test() const;
};
template<typename T> void MyTest::test() const {
map<string, T*> m;
map<string, T*>::const_iterator i = m.begin();
}
Run Code Online (Sandbox Code Playgroud)
我的编译器说:
In member function ‘void MyTest::test() const’:
test.cpp:8: error: expected `;' before ‘i’
Run Code Online (Sandbox Code Playgroud)
这是什么意思?提前谢谢了!
您有一个从属名称,您需要附加typename到const_iterator,因为它的类型取决于类型T.
template<typename T> void MyTest::test() const {
map<string, T*> m;
typename map<string, T*>::const_iterator i = m.begin();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
204 次 |
| 最近记录: |