• Notice regarding image hosts and attachments. See here.

c++ help please!

Soldato
Joined
18 Feb 2003
Posts
5,822
Location
Chester
right i'm a bit confused has to how to fix this error i've got -

error C2270: 'getx' : modifiers not allowed on nonmember functions

when using -

Code:
float getx() const // return x coord of point
{
	float getX();    // not sure what to put in here tbh
}
with the class definition -
Code:
public:
Point(float x, float y, float z); // Construct from 3 floats
float getx() const; // return x coord of point
 
Last edited:
yeah the class is called Point - although it is also present in another class under the same name. which looks like -
Code:
public:
	Coords2d(); // default constructor
	Coords2d (const Coords2d& source); // copy constructor
	Coords2d(float x, float y); // Construct from 2 floats
	Coords2d& operator= (const Coords2d& other); // assignment operator
	float getX() const;

float Coords2d::getX() const
{
	return x_;
}

and that works fine.
_________________________
since last night i've changed my function to -
Code:
float Point::getx() // return x coord of point
{
	return x;
}
and now get the error -
error C2511: 'float Point::getx(void)' : overloaded member function not found in 'Point'

and i can't remember much on overloading functions - any ideas?
 
ah, sorry, no. its all coming from different files. I've got separate header files for the class definitions and separate cpp files for each class :)
 
right looks like i forgot to actually construct anything from the Point class.

now after running through the constructors i get the error -

error C2614: 'Point' : illegal member initialization: 'x' is not a base or member
 
Back
Top Bottom