У меня есть диаграммы UML Line класса, которая показывает подробную информациюкодирования базы на UML диаграмме C++
- pOne: Point
- pTwo: Point
+ Line (ptOne: Point, ptTwo: Point)
+ getPOne() : Point
+ getPTwo() : Point
+ setPOne (pOne: Point)
+ setPTwo (pTwo: Point)
)
это то, что я сделал по моей интерпретации диаграммы UML
Line.h
#ifndef __testing__Line__
#define __testing__Line__
#include <iostream>
#include "Point"
class Line {
private:
//pOne and pTwo are objects of Point
Point pOne;
Point pTwo;
public:
Line() {
};//default Constructor
// constructor of class Line to store objects of Point(pOne,pTwo)
Line (Point pOne,Point pTwo);
// get method for objects of Point(pOne,pTwo)
Point getPOne();
Point getPTwo();
// set method for objects of a(one,two)
void setPOne (Point pOne);
void setPTwo (Point pTwo);
};
#endif /* defined(__testing__Line__) */
Line.cpp
#include "Line.h"
Line::Line (Point pOne, Point pTwo) {
setPOne(pOne);
setPTwo(pTwo);
}
Point Line::getPOne() {
return pOne;
}
Point Line::getPTwo() {
return pTwo;
}
Line::setPOne (Point pOne) {
this-> pOne = pOne;
}
Line::setATwo (Point pTwo) {
this->pTwo = pTwo;
}
и в главном CPP я попытался вызвать функцию getPOne()
main.cpp
#include "Point"
#include "Line"
int main() {
Line outputMethod;
//Invalid operands to binary expression
std::cout << outputMethod.getPOne() << std::endl;
}
Как я должен назвать getPOne() из класса линии, приведенной в описанной выше ситуации?
оператор перегрузки
//overload << operator
friend std::ostream& operator<<(std::ostream& os, Point&)
{
return os;
}
'станд :: соиЬ << outputMethod.getPOne() << станд :: епсИ;' – billz
жаль, что я пропустил на(). но я все еще получаю ошибку – user2935569
У вас есть 'operator <<' для точки? – billz