C에서 C++로 전환 할 때 클래스 기밀성에 대한 기본하지만 귀찮은 문제가 있습니다. 나는 여기서 약간의 연구를했는데, 아마도 나는 정말로 바보스럽고, yor 방법을 제대로 사용할 수 없다. 나를 도울 수 있겠 니?오버로드 된 '<<'를 통해 클래스의 개인 변수 인쇄
과부하 된 '< <'연산자를 통해 클래스의 전용 멤버를 인쇄하는 것이 문제입니다.
#include Vector.hh
#include <iostream>
using namespace std;
int main()
{
Vector Vector1;
cout << endl << " Start " << endl << endl;
cin >> Vector1;
cout << Vector1;
}
을 파일에 파일에서Vector.cpp
#include "Vector.hh"
#include <iostream>
void Vector::PrintVector(Vector Wek)
{
std::cout << Wek.Val1 << Wek.Val2 << Wek.Val3 << std::endl;
}
std::istream& operator >> (std::istream &Strm, Vector &Wek)
{
//It actually works with no problem so i'll pass it
}
std::ostream& operator << (std::ostream &Strm, Vector Wek)
{
Vector::PrintVector(Wek);
return Strm;
}
을 Vector.hh
#include <iostream>
class Vector {
double Val1, Val2, Val3;
public:
void PrintVector(Vector);
//There is also a constructor but it doesn't really matter
}
및 MAIN.CPP에 :의 코드에하자
시도 할 때 컴파일하려면 g ++가 말합니다 :
g++ -c -g -Iinc -Wall -pedantic -o obj/Vector.o src/Vector.cpp
src/Vector.cpp:12:37: error: no 'void Vector::PrintVector(Vector)' member function declared in class 'Vector'
void Vector::PrintVector(Vector Wek)
^
src/Vector.cpp: In function 'std::ostream& operator<<(std::ostream&, Vector)':
src/Vector.cpp:29:1: error: 'PrintVector' is not a member of 'Vector'
Vector::PrintVector(Wek);
make: Fatal error: Command failed for target `obj/Vector.o'
제게 기본 지식을 올바르게 배울 수 있습니까?