PDA

View Full Version : C++ subclassing




Duke Leto
Jul 30, 2009, 10:01 AM
I was making my own little clone of an NSView using C++ (to use with GLUT, so that it could be cross-platform), and I made a subclass.

My view class has a getFrame() function, and when I tried to use that function from a subclass, I got an error: "View::getFrame() referenced from:"

The function I referenced it from was the subclass's implementation of draw(), which looked like this:


void Box::draw()
{
Rect aFrame = getFrame(); // this is where the problem lies, I think
GLfloat x = aFrame.origin.x, y = aFrame.origin.y;
GLfloat width = aFrame.size.width, height = aFrame.size.height;
glColor3d(drawingColor.red, drawingColor.green, drawingColor.blue);
glBegin(GL_QUADS);
glVertex3f(x, y, 1.0f);
glVertex3f(x+width, y, 1.0f);
glVertex3f(x+width, y+height, 1.0f);
glVertex3f(x, y+height, 1.0f);
glEnd();
}



Cinder6
Jul 30, 2009, 11:25 AM
My C++ isn't the sharpest, but have you tried replacing getFrame() with View::getFrame() ?

Duke Leto
Jul 30, 2009, 11:30 AM
Yes, and with Box::getFrame().

If you want to see all the code, I can try to upload it or post it. (So far there is an "NSMutableArray", an "NSEnumerator", and an "NSView".

EDIT::
Woah!!! I am so stupid. I forgot to define getFrame()!
Still, if you want the code, I want to share it. So far the commenting is alright, memory management has not been tested though.
Woohoo! subviews work *with* relative coordinates! I can put a box inside of a box inside of a box!