이 CRac 클래스가 있는데 멤버에게 문제가 생깁니다. CCP가 파일에서 C++ : 클래스 X에는 Y라는 이름의 멤버가 없습니다
//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
나는
#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;
}
이 그리고 내가 그것을 실행할 때, 출력은
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’
이다 나는이 포인터와 그것을 해결하기 위해 시도하지만 계속 같은 실수를했습니다. 고마워요!
Racional에는 CRac이 아닌 num이라는 회원이 있습니다. 어쩌면 당신은'res.nc.' 대신'res.rac.num'을 의미했을까요? (otroRac.num 및 rac.num과 동일). 또한 rac 회원은 비공개이므로 otroRac 객체에 직접 액세스 할 수 없으므로 getRac() 메소드를 추가해야합니다. – Mesop
'add()'는별로 의미가 없습니다. 'CRac' 객체를 생성하고 수정 한 다음 버립니다. 'a.add (b)'가'a'를 수정하기를 원한다면,'add()'는'const'가되어서는 안되며,'rac.num'을 사용해야합니다. 즉,'this-> rac.num ''res.rac.num'이 아닙니다. 또한,이 메소드들 중 많은 것들이 연산자 오버로드로 더 이해하기 쉽습니다 :'friend std :: istream & operator >> (std :: istream &, CRac &)','write()'와'read() CRac & operator = (const CRac &)','add()'를'CRac & operator + = (const CRac &)'와 같이 ostream & operator << (std :: ostream &, const CRac &)','asignarVal' –
이 함수로 수행하고자하는 것은 두 개의 객체를 더하고 결과를 다른 객체에 저장하는 것입니다. 나는 연산자 +를 오버로드하려고 시도했으나 출력은 동일합니다. class bblRac에는 ... – Rooxrod