【发布时间】:2016-09-04 21:56:05
【问题描述】:
我正在学习 C++,在我的课堂上我们将讨论构造函数和重载构造函数,我只是想知道如何让这个重载构造函数工作。
我在 Double.cpp 中收到错误 C3867“'Integer::toInt': non-standard syntax; use '&' to create a pointer to member”
过去 2 小时我一直坚持这一点,现在我不知道如何继续前进。感谢任何帮助。
双.h:
#ifndef DOUBLE
#define DOUBLE
class Integer;
class Double
{
public:
double num;
public:
void equal(double value);
double toDouble()const;
// Constructors
Double();
Double(Double &val);
Double(double val);
Double(Integer &val); // This is the trouble one
};
#endif // !DOUBLE
Double.cpp
void Double::equal(double value)
{
this->num = value;
}
Double::Double()
{
this->equal(0.0);
}
Double::Double(Double &val)
{
this->equal(val.num);
}
Double::Double(double val)
{
this->equal(val);
}
Double::Double(Integer &val)
{
this->equal(val.toInt); // I get the error right here
}
整数.h:
#ifndef INTEGER
#define INTEGER
class Double;
class Integer
{
private:
int num;
public:
void equal(int value);
int toInt()const;
//Constructors
Integer();
Integer(Integer &val);
Integer(int val);
};
#endif // !INTEGER
和整数.cpp
int Integer::toInt()const
{
return this->num;
}
//Constructer
Integer::Integer()
{
this->equal(0);
}
Integer::Integer(Integer &val)
{
this->equal(val.num);
}
Integer::Integer(int val)
{
this->equal(val);
}
【问题讨论】:
-
这是编译器说你不小心传递了一个变量(
val.toInt)而不是调用函数val.toInt()的方式。以下是MSVS error C3867的完整详细信息
标签: c++