zoukankan      html  css  js  c++  java
  • 关于类模版迭代器提出时的错误

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

    类似于这样。

    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直接通过

  • 相关阅读:
    gTest&gMock learning
    机器学习 delay learning
    c++ learning
    2017 湘潭邀请赛&JSCPC G&J
    mapreduce&GFS&bigtable learning
    golang learning
    高斩仙的北京历险记
    python learning
    Codeforces Round #448 (Div. 2) B
    python之callable
  • 原文地址:https://www.cnblogs.com/ziolo/p/3093992.html
Copyright © 2011-2022 走看看