我是 C++ 编程的新手……一年前我开始用 C# 编程,所以我在一些非常基本的东西上失败了……我想……我创建了一个名为 vector 的类,它是 3d 中的一个点空间的标题如下所示:
class vec3
{
double x, y, z;
public:
vec3();
vec3(double x, double y, double z);
double calculateLLength(void);
double distance(double x1, double y1, double z1);
double distance(const vec3 &vec);
~vec3(void);
};
在此之后,我应该编写一个名为 sphere 的类,其中心点是来自我的向量类的向量,它看起来很简单(球体标题):
#pragma once
#include "vec3.h"
class Sphere
{
vec3 center1;
double x, y, z;
double radius1;
static const double PI;
public:
//constructs
Sphere(double x, double y, double z, double radius);
Sphere(vec3 center1, double radius);
//Methods
bool inside(const vec3 ¢er);
bool overlap(const Sphere &sphere);
double area();
double volume();
~Sphere(void);
};
我得到的错误是:
错误 LNK1120:1 未解决的外部
我试着用谷歌搜索这个,周六的大部分时间都在试图修复它,但不能....
(如果有人需要,这里是 cpp 文件!)
球体.cpp:
#include "StdAfx.h"
#include "Sphere.h"
#include "vec3.h"
#include <math.h>
const double Sphere::PI = 3.1415926535;
Sphere::Sphere(double centerX, double centerY, double centerZ, double radius)
{
vec3 center(centerX, centerY, centerZ);
radius1 = radius;
}
Sphere::Sphere(vec3 center, double radius)
{
center1 = center;
radius1 = radius;
}
bool Sphere::inside(const vec3 ¢er)
{
if(radius1 < center1.distance(center))
return false;
else
return true;
}
bool Sphere::overlap(const Sphere &sphere)
{
if(this->center1.distance(sphere.center1) < radius1 + sphere.radius1)
return true;
else
return false;
}
double Sphere::area()
{
}
double Sphere::volume()
{
}
Sphere::~Sphere(void)
{
}
vec3.cpp:
#include "StdAfx.h"
#include "vec3.h"
#include <math.h>
vec3::vec3(double x, double y, double z)
{
this->x=x;
this->y=y;
this->z=z;
}
double vec3::calculateLLength()
{
return sqrt((x*x) + (y*y) + (z*z));
}
double vec3::distance(double x1, double y1, double z1)
{
return sqrt( ((this->x - x1)*(this->x - x1)) + ((this->y - y1)*(this->y - y1)) + ((this->z - z1)*(this->z - z1)) );
}
double vec3::distance(const vec3 &vec)
{
return sqrt( ((this->x - vec.x)*(this->x - vec.x)) + ((this->y - vec.y)*(this->y - vec.y)) + ((this->z - vec.z)*(this->z - vec.z)) );
}
vec3::~vec3(void)
{
}