저는 계산을 수행하기 위해 VectorMath 클래스에 정적 메서드를 호출하는 Vector3D 클래스를 작성하고 있습니다. 내가 컴파일 할 때,이 얻을 :정적 메서드에 대한 C++ 링커 문제
bash-3.1$ g++ VectorMath.cpp Vector3D.cpp /tmp/cc5cAPia.o: In function `main': Vector3D.cpp:(.text+0x4f7): undefined reference to 'VectorMath::norm(Vector3D*)' collect2: ld returned 1 exit status
코드 :
VectorMath.h :
#ifndef VECTOR3D_H
#include "Vector3D.h"
#endif
class VectorMath {
public:
static Vector3D* calculatePerpendicularVector(Vector3D*, Vector3D*);
static Vector3D* norm(Vector3D*);
static double length(Vector3D*);
};
VectorMath.cpp
#include "VectorMath.h"
Vector3D* norm(Vector3D* vector) { // can't be found by linker
// do vector calculations
return new Vector3D(xHead, yHead, zHead, xTail, yTail, zTail);
}
// other methods
값 Vector3D. cpp
#include "Vector3D.h"
#include "VectorMath.h"
// ...
// vector implementation
// ...
int main(void) {
Vector3D* v = new Vector3D(x, y, z);
Vector3D* normVector = VectorMath::norm(v); // error here
}
왜 링커가 VectorMath::norm
메서드를 찾지 못합니까?
이것은 "그러나 도움이되지 않습니다 ..."는 정보가 충분하지 않습니다. 그게 무슨 뜻 이죠? 같은 오류, 다른 오류? – GManNickG