codeblocks 버전 10.05에 문제점이 있습니다. 나는 C++ 프로젝트를 만들고, 나는이 같은 프로그램을 작성 :코드 블록에서 링크가 작동하지 않습니다!? (정의되지 않은 참조 ...)
MAIN.CPP
#include <iostream>
#include "vectorddd.hpp"
using namespace std;
int main()
{
vector3D<int> tesztinttomb;
tesztinttomb.saveout("igen.dat");
return 0;
}
헤더 파일 (vectorddd.hpp) :
#ifndef VECTORDDD_HPP_INCLUDED
#define VECTORDDD_HPP_INCLUDED
#include <iostream>
template <class T>
class vector3D {
T *x;
T *y;
T *z;
int meret;
public:
void saveout(char* FileName);
vector3D(int Meret=0) : x(new T[meret]), y(new T[Meret]), z(new T[Meret]), meret(Meret) {}
~vector3D() { delete [] x; delete [] y; delete [] z; }
};
#endif // VECTORDDD_HPP_INCLUDED
구현 파일 (vectorddd.cpp를) :
#include "vectorddd.hpp"
template <class T>
void vector3D<T>::saveout(char* FileName) {
int i=0;// I know this is stupid... but the emphasis is on the linking problem
}
그리고 그냥 연결되지 않습니다. .cpp 파일을 확인하고 속성 -> 빌드 옵션에서 설정을 컴파일해야한다는 것을 알고 있습니다. 그리고 나는 어떤 문제를 찾을 수없는, 그러나 다만 항상 같은 쓰기된다
In function `main':
undefined reference to `vector3D<int>::saveout(char*)'
||=== Build finished: 1 errors, 0 warnings ===|
을 그리고 내 .HPP 파일로 .CPP 파일 구현을 넣을 경우 올바르게 작동합니다. 그러나 이것이 코드 블럭이 작동하는 방식이 아닙니다.
[템플릿 정의를 헤더에 가야한다] (HTTP : // WWW를 .parashift.com/C++ - faq/templates.html # faq-35.13), 이것은 CB와는 아무런 관련이 없습니다. – ildjarn
http://stackoverflow.com/q/115703/1214731 자세한 내용은 여기를 참조하십시오. – tmpearce