Evin Evin - 3 months ago 40
C++ Question

C++ Visual Studio non-standard syntax use '&' to create a pointer to member

I'm learning C++ and in my class we are going over Constructors and Overload Constructor, and I just can figure out how to get this overload constructor working.

I get error C3867 " 'Integer::toInt': non-standard syntax; use '&' to create a pointer to member" in Double.cpp

I have stuck on this for the past 2 hours now I have no clue how to move forward any help is appreciated.

Double.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
}


Integer.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


and 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);
}

Answer

You need to call the toInt method of Integer:

this->equal(val.toInt());