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

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

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

回答1:

You need to call the toInt method of Integer:

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!