expected initializer
Dec 4, 2012 at 9:31pm UTC
Hello,
I receive the error "expected initializer" at row getX and getY of Point.cpp file. Please, can you help me out finding the error?
Thank you in advance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <math.h>
#include <stdlib.h>
#ifndef POINT_H_
#define POINT_H_
class Point {
private :
float x;
float y;
public :
Point();
Point(float x, float y);
~Point();
float getX();
float getY();
};
#endif /* POINT_H_ */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <math.h>
#include <stdlib.h>
#ifndef POINT_H_
#define POINT_H_
class Point {
private :
float x;
float y;
public :
Point();
Point(float x, float y);
~Point();
float getX();
float getY();
};
#endif /* POINT_H_ */
1 2 3 4 5 6 7 8 9 10 11
#include "Point.h"
#include <iostream>
using namespace std;
int main(){
Point point(3.5,6.7);
cout<< "Point" << point.getX() << point.getY() << endl;
~point();
cout<< "Point" << point.getX() << point.getY() << endl;
}
Dec 4, 2012 at 10:22pm UTC
What is line 7 trying to do? The rest of the code looks OK provided the definitions are good.
Dec 5, 2012 at 2:22pm UTC
Dear Zhuge,
Mistakenly, I've posted the code of Poin.h twice, you need Point.ccp.
Please, look at the code hereafter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "Point.h"
Point::Point(float xx, float yy):x(xx),y(yy){}
Point::Point(){
x = 0;
y = 0;
}
Point::~Point(){
x = 0;
y = 0;
}
float ::Point getX(){
return x;
}
float ::Point getY(){
return y;
}
Topic archived. No new replies allowed.