Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:20:33+00:00 2026-05-17T00:20:33+00:00

hi im trying to pass some values to a class but it wont let

  • 0

hi im trying to pass some values to a class but it wont let me it says invalid use of class ‘Figure’ im trying to send 3 values x,y,z and thats all but it wont let me heres what im trying to do…

here is the main.cpp and the function that calls the class Figure

 for (j = 0; j < num_elems; j++) {
    /* grab and element from the file */
    vlist[j] = (Vertex *) malloc (sizeof (Vertex));
    ply_get_element (ply, (void *) vlist[j]);


    int vert=sprintf(szFile,"vertex: %g %g %g", vlist[j]->x, vlist[j]->y, vlist[j]->z);
    /* print out vertex x,y,z for debugging */
    TextOut(hDC,600,j*20,szFile,vert);
   DrawFig->Figure(vlist[j]->x, vlist[j]->y, vlist[j]->z);
  }

The error is here

   DrawFig->Figure(vlist[j]->x, vlist[j]->y, vlist[j]->z);
  }

Here is the WM_CREATE: where i initialize everything

case WM_CREATE:
        hDC = GetDC(hWnd);
     //ShowWindow(g_hwndDlg,SW_SHOW);
    hRC=wglCreateContext(hDC);
    wglMakeCurrent(hDC,hRC);
     g_hwndDlg = CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hWnd,DialogProc);

    DrawFig= new Figure(1.0,1.0,1.0);
    initGL();
     break;

here is the Figure.h

class Figure
{
    public:
        Figure(float x,float y,float z);
        void Draw();
        float paramx(){
        return x1;
        }
        float paramy(){
        return y1;
        }
        float paramz(){
        return z1;
        }
    protected:
    private:
    float x1,y1,z1;
    list <Figure> m_vertices;
};

and here is the Figure.cpp

Figure::Figure(float x,float y,float z){
    this->x1=x;
this->y1=y;
this->z1=z;
m_vertices.push_back(Figure(x1, y1, z1));
}

void Figure::Draw()
{
    list<Figure>::iterator p = m_vertices.begin();
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();
    gluLookAt(0.0,0.0,4.0,0.0,0.0,0.0,0.0,1.0,0.0);

    glColor3f(0.7f,1.0f,0.3f);
    glBegin(GL_LINE_LOOP);
    while(p != m_vertices.end()){
        glNormal3f(p->paramx(),p->paramy(),p->paramz());
        glVertex3f(p->paramx(),p->paramy(),p->paramz());
        p++;
    }
    glEnd();
}

any ideas? this is opengl,c++ and im using codeblocks 10.05 just in case
oh yeah im initializing it at the main.h like this DrawFig* Figure;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:20:34+00:00Added an answer on May 17, 2026 at 12:20 am

    @dark_charlie’s answer is almost correct. Here is a better version that will actually work, but still probably isn’t what you want:

    class Figure  {
      // ...
    public:
      void set(float x, float y, float z);
      // ...
    };
    
    void Figure::set(float x, float y, float z)
    {
      // Your original code from the constructor
      this->x1 = x;
      this->y1 = y;
      this->z1 = z;
    }
    
    Figure::Figure(float x, float y, float z)
    {
      // In the constructor call the newly created set function
      set(x, y, z);
      m_vertices.push_back(Figure(x1, y1, z1));
    }
    
    
    // Replace the faulty line with this:
    DrawFig->set(vlist[j]->x, vlist[j]->y, vlist[j]->z);
    

    Now, this is almost certainly not what you want. But it’s also really hard to figure out what you do want. You have a design problem. The design problem is that Figure has two responsibilities. It is both a point in space, and a set of points describing a figure. This confusion of responsibilities is leading your class to not actually be able to fill either of them particularly well.

    You need two classes. You need a Point class and a Figure class. The Figure class should allow you to set the location of the figure as well as letting you add points to the figure’s outline.

    The huge clue that something is wrong is this list<Figure> m_vertices;. It’s very rare that a class conceptually contains instances of itself. And usually when you do it you’re building your own data structure like a tree or a list and then the class contains pointers to instances of itself.

    Also, the fact that @dark_charlie’s simple fix resulted in infinite recursion is another huge clue that something is wrong.

    I’m guessing this is a homework assignment, so this is all the help I will give you aside from telling you that I think you already have a Point class that you call Vertex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just trying to pass some values but it's throwing an error all the
I'm an encryption novice trying to pass some values back and forth between systems.
I'm trying to use the Sprite Class in Microsoft.DirectX.Direct3D to draw some sprites to
I'm trying to pass some files from one app to another. I communicate the
I'm trying to pass a dynamic, user created object through AJAX to some C#.
I am trying pass class as value in hashmap. I need to get the
Trying to pass something to something else. Says undefined. Not sure how or why.
I'm trying to write a class that has a generic member variable but is
I'm testing some code(trying to make it faster but also trying to understand the
I am trying to pass several values through an IMultiValueConverter to a command (as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.