0

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);
}
Evin
  • 15
  • 4
  • That's the compiler's way of saying you accidentally passed a variable (`val.toInt`) instead of calling the function `val.toInt()`. Here are complete details for [MSVS error C3867](https://msdn.microsoft.com/en-us/library/b0x1aatf.aspx) – paulsm4 Sep 04 '16 at 22:06

1 Answers1

2

You need to call the toInt method of Integer:

this->equal(val.toInt());
js441
  • 1,134
  • 8
  • 16
  • 3
    To add to your (perfectly accurate) answer, the error message refers to an _extension_ of old `VS` versions (some people would call it a bug), consisting in that you could take the address of a member function just like that, `val.toInt`, while the only standard syntax is `&Integer::toInt`. – rodrigo Sep 04 '16 at 22:07