| | |
illegal token for "::"
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
For the line Point::setPoint(... it tells me that it is invalid and I set it to Point::&setPoint(.. with then stats it is a illegal operation. I'm a little lost on this one anyone mine pointing me in the right direction.
C++ Syntax (Toggle Plain Text)
class Point { public: Point(double=0.0, double=0.0); Point &setPoint(double xPoint, double yPoint); double distance(Point & p); void print() const; private: double x; double y; }; Point::setPoint(double xPoint, double yPoint) { xPoint = x; yPoint = y; return *this; } double Point::distance(Point &p) { double dis; dis = sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)); return dis; } void Point::print() const { cout << "(" << x << ", " << y << ")" << endl; } int main() { Point myObject, myObject2; myObject.setPoint(4,5).print(); myObject2.setPoint(3,4).print(); return 0; }
•
•
Join Date: Jan 2008
Posts: 3,817
Reputation:
Solved Threads: 501
Everything but a constructor needs a return type, so I assume you want this:
since it matches this declaration in the Point class (see red):
C++ Syntax (Toggle Plain Text)
Point& Point::setPoint(double xPoint, double yPoint)
since it matches this declaration in the Point class (see red):
class Point
{
public:
Point(double=0.0, double=0.0);
Point &setPoint(double xPoint, double yPoint);
double distance(Point & p);
void print() const;
private:
double x;
double y;
};![]() |
Other Threads in the C++ Forum
- Previous Thread: Segmentation Fault, recursive function for Minesweeper
- Next Thread: trying to run a string as a command
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






