我正在關注這個YouTube tutorial to build an FPS game in C++,但我遇到了一個我無法解決的錯誤;鏈接器錯誤LNK2019:錯誤鏈接2019 C++
錯誤1個錯誤LNK2019:解析外部符號 「公共:__thiscall的Vector3D ::〜的Vector3D(無效)」(?? 1Vector3d @@ @ QAE XZ)在函數「類的std ::引用basic_ostream > & __cdecl運算符< <(class std :: basic_ostream> &,class Vector3d)「(?? 6 @ YAAAV?$ basic_ostream @ DU?$ char_traits @ D @ std @@@ std @@ AAV01 @ VVector3d @@@ Z )
C:\用戶\丹尼爾\的文檔\ Visual Studio的 2012 \項目\ Project2的\ Project2的\ Vector3d.obj Project2的
我需要做些什麼來解決這個問題?
這是我Vector3d
類Vector3d.h
聲明:
#ifndef VEC_H
#define VEC_H
#include<iostream>
#include<cmath>
class Vector3d
{
public:
float x,y,z;
Vector3d(void);
Vector3d(float,float);
Vector3d(float,float,float);
~Vector3d(void);
float dotPrudect(const Vector3d& vec2);
Vector3d crossproduct(const Vector3d& vec2);
float lenght();
void normalize();
void change(float a,float b,float c);
void change(Vector3d& vec2);
void change(Vector3d vec2);
void changeX(float a);
void changeY(float b);
void changeZ(float c);
Vector3d operator+(const Vector3d& vec2);
Vector3d operator-(const Vector3d& vec2);
Vector3d operator*(const float& num);
Vector3d operator/(const float& num);
Vector3d& operator+=(const Vector3d& vec2);
Vector3d& operator-=(const Vector3d& vec2);
Vector3d& operator*=(const float& num);
Vector3d& operator/=(const float& num);
bool operator==(const Vector3d& vec2);
bool operator!=(const Vector3d& vec2);
friend std::ostream& operator<<(std::ostream& out,Vector3d vec2);
};
#endif
和相應的Vector3d.cpp
實現:
#include "Vector3d.h"
Vector3d::Vector3d()
{
x=y=z=0;
}
Vector3d::Vector3d(float a,float b)
{
x=a;
y=b;
z=0;
}
Vector3d::Vector3d(float a,float b,float c)
{
x=a;
y=b;
z=c;
}
float Vector3d::dotPrudect(const Vector3d& vec2)
{
return (x*vec2.x+y*vec2.y+z*vec2.z);
}
Vector3d Vector3d::crossproduct(const Vector3d& vec2)
{
return (Vector3d(y*vec2.z-z*vec2.y,x*vec2.z-z*vec2.x,x*vec2.y-y*vec2.x));
}
float Vector3d::lenght()
{
return (sqrt(x*x+y*y+z*z));
}
void Vector3d::change(float a,float b,float c)
{
x=a;
y=b;
z=c;
}
void Vector3d::change(Vector3d vec)
{
x=vec.x;
y=vec.y;
z=vec.z;
}
void Vector3d::change(Vector3d& vec)
{
x=vec.x;
y=vec.y;
z=vec.z;
}
void Vector3d::changeX(float a)
{
x=a;
}
void Vector3d::changeY(float b)
{
y=b;
}
void Vector3d::changeZ(float c)
{
z=c;
}
void Vector3d::normalize()
{
float len=lenght();
if(len!=0)
{
x/=len;
y/=len;
z/=len;
}
}
Vector3d Vector3d::operator+(const Vector3d& vec2)
{
return (Vector3d(x+vec2.x,y+vec2.y,z+vec2.z));
}
Vector3d Vector3d::operator-(const Vector3d& vec2)
{
return (Vector3d(x-vec2.x,y-vec2.y,z-vec2.z));
}
Vector3d Vector3d::operator*(const float& num)
{
return (Vector3d(x*num,y*num,z*num));
}
Vector3d& Vector3d::operator+=(const Vector3d& vec2)
{
x+=vec2.x;
y+=vec2.y;
z+=vec2.z;
return *this;
}
Vector3d& Vector3d::operator-=(const Vector3d& vec2)
{
x-=vec2.x;
y-=vec2.y;
z-=vec2.z;
return *this;
}
Vector3d& Vector3d::operator*=(const float& num)
{
x*=num;
y*=num;
z*=num;
return *this;
}
Vector3d& Vector3d::operator/=(const float& num)
{
if(num!=0)
{
x/=num;
y/=num;
z/=num;
}
return *this;
}
bool Vector3d::operator==(const Vector3d& vec2)
{
return (x==vec2.x && y==vec2.y && z==vec2.z);
}
bool Vector3d::operator!=(const Vector3d& vec2)
{
return (x!=vec2.x && y!=vec2.y && z!=vec2.z);
}
std::ostream& operator<<(std::ostream& out,Vector3d vec2)
{
out << vec2.x << "\t" << vec2.y << "\t" << vec2.z << std::endl;
return out;
}
不要隱藏鏈接後面的相關信息。您鏈接的頁面將會消失,您的問題將對其他人無用。 – Oswald