【发布时间】:2016-08-22 18:49:22
【问题描述】:
我正在尝试编写光线追踪器,但由于以下错误而无法编译我的程序:
src\util\Ray.cpp:在构造函数“Ray::Ray()”中:src\util\Ray.cpp:8:17: 错误:不匹配调用“(Vector3D) (double, double, double)”
o(0.0, 0.0, 0.0); ^ makefile.mak:31: 目标“Ray.o”的配方失败 mingw32-make: *** [Ray.o] 错误 1
这是代码:
//Vector3D.h
#ifndef __VECTOR3D__
#define __VECTOR3D__
class Vector3D{
public:
float x;
float y;
float z;
public:
Vector3D(void);
Vector3D(const float&, const float&, const float&);
Vector3D(const Vector3D& obj);
};
#endif
//Vector3D.cpp
#include <iostream>
#include "Vector3D.h"
using namespace std;
Vector3D::Vector3D(void){
x = 0.0;
y = 0.0;
z = 0.0;
}
Vector3D::Vector3D(const float &p_x, const float &p_y, const float &p_z){
x = p_x;
y = p_y;
z = p_z;
}
Vector3D::Vector3D(const Vector3D& obj){
x = obj.x;
y = obj.y;
z = obj.z;
}
//Ray.h
#ifndef __RAY__
#define __RAY__
#include "Vector3D.h"
class Ray{
public:
Vector3D o;
Vector3D d;
public:
Ray(void);
};
#endif
//Ray.cpp
#include "Ray.h"
Ray::Ray(void){
o(0.0, 0.0, 0.0);
}
我不知道这里出了什么问题,有人可以解释一下吗?
【问题讨论】:
-
可能是
this->o = Vector3D(0.0, 0.0, 0.0);而不是o(0.0, 0.0, 0.0);? -
工作,谢谢!你愿意详细说明为什么我必须这样做吗?
-
OT:您的包含警卫是非法的。 stackoverflow.com/questions/228783/…
-
o(0.0, 0.0, 0.0);在Vector3D对象上调用operator()重载...
标签: c++ constructor instantiation