시도 ss<<(Msg const&)in
아마도 연산자를 Greeting
클래스의 친구로 만들어야합니다.
#include "iostream"
#include "string"
typedef enum { TypeGreeting} MsgType;
class Msg {
friend inline std::ostream& operator <<(std::ostream& ss,Msg const& in);
int target;
public:
Msg(int target): target(target) { }
virtual ~Msg() { };
virtual MsgType GetType()=0;
};
inline std::ostream& operator <<(std::ostream& ss,Msg const& in) {
return ss << "Target " << in.target;
}
class Greeting : public Msg {
friend inline std::ostream& operator <<(std::ostream& ss,Greeting const& in);
std::string text;
public:
Greeting(int target,std::string const& text) : Msg(target),text(text) {};
MsgType GetType() { return TypeGreeting; }
};
inline std::ostream& operator <<(std::ostream& ss,Greeting const& in) {
return ss << (Msg const&)in << " Text " << in.text;
}
int _tmain(int argc, _TCHAR* argv[])
{
Greeting grt(1,"HELLZ");
std::cout << grt << std::endl;
return 0;
}
문제가 해결되지 않았지만 문제가 해결되었습니다.
이는 const의 정확성에 위배됩니다. –
'(Msg) in' 대신'static_cast (in)'이라고 쓰십시오. –
"in.text"? 어쨌든 컴파일 오류를 줄 점 표기법을 사용하여 개인 회원에 액세스하고 있습니다. 기밀 회원 가입은 getters와 setters 함수에 의해서만 수행 될 수 있습니다. – Arunmu