C++ subclassing

Discussion in 'Mac Programming' started by Duke Leto, Jul 30, 2009.

  1. Duke Leto macrumors regular

    Mar 17, 2008
    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);
    	glVertex3f(x, y, 1.0f);
    	glVertex3f(x+width, y, 1.0f);
    	glVertex3f(x+width, y+height, 1.0f);
    	glVertex3f(x, y+height, 1.0f);
  2. Cinder6 macrumors 6502


    Jul 9, 2009
    My C++ isn't the sharpest, but have you tried replacing getFrame() with View::getFrame() ?
  3. Duke Leto thread starter macrumors regular

    Mar 17, 2008
    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".

    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!

Share This Page