关于类模版迭代器提出时的错误

今天在写迭代器的时候,准备做模版,于是把实现从声明类中提出来。写到声明的下面。

类似于这样。

Ca.H

class A
{
public:
  A();
}

A::A()
{

}

准备把迭代器的构造函数和重载的运算符函数都提出来,结果发现报错。

同样的代码。在VC6.0中和2005结果就不一样。

#include <iostream>
using std::cout;
using std::endl;

template <typename T1>
class A
{
public:
  class B
  {
  public:
    B();
  };
public:
  A();
};


template <typename T1>
A<T1>::A()
{
    cout << "sss"<<endl;
}

template <typename T1>
A<T1>::B::B()
{
    cout << "sss"<<endl;
}

int main(int argc, char* argv[])
{
  A<int>::B the;
  return 0;
}

VC6.0报链接错误:

--------------------Configuration: Virtual_Test - Win32 Debug--------------------
Compiling...
Virtual_Test.cpp
Linking...
Virtual_Test.obj : error LNK2001: unresolved external symbol "public: __thiscall A<int>::B::B(void)" (??0B@?$A@H@@QAE@XZ)
Debug/Virtual_Test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

而2005直接通过

 

posted @ 2013-05-22 23:49  0x苦行僧  阅读(189)  评论(0编辑  收藏  举报