illegal token for "::"

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 18
Reputation: Dontais is an unknown quantity at this point 
Solved Threads: 0
Dontais's Avatar
Dontais Dontais is offline Offline
Newbie Poster

illegal token for "::"

 
0
  #1
Mar 16th, 2009
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.
  1. class Point
  2. {
  3. public:
  4. Point(double=0.0, double=0.0);
  5. Point &setPoint(double xPoint, double yPoint);
  6. double distance(Point & p);
  7. void print() const;
  8. private:
  9. double x;
  10. double y;
  11. };
  12.  
  13. Point::setPoint(double xPoint, double yPoint)
  14. {
  15. xPoint = x;
  16. yPoint = y;
  17. return *this;
  18. }
  19.  
  20. double Point::distance(Point &p)
  21. {
  22. double dis;
  23. dis = sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
  24. return dis;
  25. }
  26.  
  27. void Point::print() const
  28. {
  29. cout << "(" << x << ", " << y << ")" << endl;
  30. }
  31.  
  32. int main()
  33. {
  34. Point myObject, myObject2;
  35. myObject.setPoint(4,5).print();
  36. myObject2.setPoint(3,4).print();
  37. return 0;
  38. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,817
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: illegal token for "::"

 
0
  #2
Mar 17th, 2009
Everything but a constructor needs a return type, so I assume you want this:

  1. 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;
	};
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC