我想實現派生自模板的PointArray類。這裏是什麼PointArray我的HPP文件的樣子:LNK2019從模板派生時出錯
#ifndef POINTARRAY_H
#define POINTARRAY_H
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "Array.hpp"
using namespace Abhishek::CAD;
using namespace Abhishek::CONTAINERS;
namespace Abhishek
{
namespace CONTAINERS
{
class PointArray : public Array<Point>
{
public:
PointArray();//Default constrcutor.
PointArray(int size);//Constructor with size argument.
PointArray(const PointArray& arr);//Copy constructor.
~PointArray();//Destructor.
double Length() const;//Length function.
};
}
}
#endif
我CPP是這樣的:
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "PointArray.hpp"
using namespace Abhishek::CAD;
using namespace Abhishek::CONTAINERS;
namespace Abhishek
{
namespace CONTAINERS
{
//Default constructor.
PointArray::PointArray(): Array<Point>()
{
cout<<"Point arr default cons"<<endl;
}
//Constructor with size argument.
PointArray::PointArray(int size) : Array<Point>(size)
{
}
//Copy constructor.
PointArray::PointArray(const PointArray& arr) : Array<Point>(arr)
{
}
//destrcutor.
PointArray::~PointArray()
{
}
}
}
我得到的LNK錯誤:
error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::Array<class Abhishek::CAD::Point>(void)" ([email protected]@[email protected]@@@[email protected]@@[email protected]) referenced in function "public: __thiscall Abhishek::CONTAINERS::PointArray::PointArray(void)" ([email protected]@[email protected]@[email protected])
1>PointArray.obj : error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::Array<class Abhishek::CAD::Point>(int)" ([email protected]@[email protected]@@@[email protected]@@[email protected]@Z) referenced in function "public: __thiscall Abhishek::CONTAINERS::PointArray::PointArray(int)" ([email protected]@[email protected]@[email protected]@Z)
1>PointArray.obj : error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::Array<class Abhishek::CAD::Point>(class Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point> const &)" ([email protected]@[email protected]@@@[email protected]@@[email protected]@@Z) referenced in function "public: __thiscall Abhishek::CONTAINERS::PointArray::PointArray(class Abhishek::CONTAINERS::PointArray const &)" ([email protected]@[email protected]@[email protected]@@Z)
1>PointArray.obj : error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::~Array<class Abhishek::CAD::Point>(void)" ([email protected]@[email protected]@@@[email protected]@@[email protected]) referenced in function [email protected]@[email protected]@[email protected]$0
1>C:\Users\Rambo\Documents\Level 6\Section 4.2b\Exercise 3\Debug\Exercise 3.exe : fatal error LNK1120: 4 unresolved externals
我不明白爲什麼這會正在發生。我包含了所有相關的頭文件和CPP文件。如果任何人都可以幫助,我會非常感激。
定義類Point的地方在哪裏? – juanchopanza
讓我猜測:'Array'模板的實現在「Array.cpp」中,而不是在「Array.hpp」中? – molbdnilo
[什麼是未解決的外部問題,我該如何解決?答案:模板實現不可見](http://stackoverflow.com/a/12574417/673730)。 –