C++ subclassing

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

  1. macrumors regular

    Joined:
    Mar 17, 2008
    #1
    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:

    Code:
    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();
    }	
    
     
  2. macrumors 6502

    Cinder6

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

    Joined:
    Mar 17, 2008
    #3
    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!
     

Share This Page