[英]c++: Class X has no member named Y
I´ve got this CRac class and it´s giving me some problems with its members. 我参加了这个CRac课程,它给我带来了一些会员问题。
//Definition TAD CRac.hpp
#ifndef CRAC_H
#define CRAC_H
namespace bblRac{
struct Racional{
int num, denom;
};
class CRac{
public:
CRac();
void read();
void asignarVal (const CRac& otroRac);
void write();
void add(const CRac& otroRac)const;
private:
Racional rac;
void simplif();
}; //End of class CRac
} //End of namespace bblrac
#endif
In a ccp file I have 在一个ccp文件中
#include "CRac.hpp"
using namespace bblRac;
void CRac::add(const CRac& otroRac)const{
CRac res;
res.num= rac.num + otroRac.num; //line 98
res.denom= rac.denom + otroRac.denom;
}
And when I run it, the output is 当我运行它时,输出是
CRac.cpp:98: error: ‘class bblRac::CRac’ has no member named ‘num’
CRac.cpp:98: error: ‘const class bblRac::CRac’ has no member named ‘num’
CRac.cpp:99: error: ‘class bblRac::CRac’ has no member named ‘denom’
CRac.cpp:99: error: ‘const class bblRac::CRac’ has no member named ‘denom’
I have tried to fix it with the pointer this, but it continues giving the same mistake.. Thank you! 我试图用指针this来修复它,但是它继续出现同样的错误..谢谢!
This will fix it. 这将解决它。
#include "CRac.hpp"
using namespace bblRac;
void CRac::add(const CRac& otroRac)const{
CRac res;
res.rac.num= rac.num + otroRac.rac.num; //line 98
res.rac.denom= rac.denom + otroRac.rac.denom;
}
Your CRac
class contains a Racional
member variable, num
and denom
are not members of CRac
. 您的
CRac
类包含一个Racional
成员变量, num
和denom
不是成员的CRac
。
res.rac.num = whatever;
otroRac.rac.num = whatever;
Please look your code over before you hit copy/paste into StackOverflow. 在将复制/粘贴到StackOverflow中之前,请先查看代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.