Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

class conversion with c++

Options
  • 02-12-2003 12:33pm
    #1
    Closed Accounts Posts: 222 ✭✭


    Hey ... I'm getting this compiler error: cannot convert from 'class cuboid *' to 'class cuboid'
    No constructor could take the source type, or constructor overload resolution was ambiguous

    Which I don't understand because I have everything declared as ints... see...

    class cuboid{
    private:
    GLuint x_, y_, z_;
    GLuint cube_no_;

    public:

    cuboid(GLuint x, GLuint y, GLuint z, GLuint cube_no);
    void draw_cuboid();
    };

    and the constructor:

    cuboid::cuboid(GLuint x, GLuint y, GLuint z, GLuint cube_no){
    x_= x; y_= y; z_= z; cube_no_= cube_no;
    }

    and this is where I'm calling it:

    cuboid inital = new cuboid(xloop, yloop, zloop, count);
    inital.draw_cuboid();
    count++;

    xloop, yloop and zloop are all declared as GLuint


Comments

  • Registered Users Posts: 4,185 ✭✭✭deadl0ck


    Your problem is here:

    cuboid inital = new cuboid(xloop, yloop, zloop, count);

    new allocates memory and returns a pointer to it

    You should have :

    (a)
    cuboid* inital = new cuboid(xloop, yloop, zloop, count);

    or

    (b)
    cuboid inital(xloop, yloop, zloop, count);


  • Closed Accounts Posts: 222 ✭✭The Second


    hey I went for B ... and it worked.. .cheers :D


  • Registered Users Posts: 79 ✭✭tendofan


    Don't forget that you have to delete the object manually.

    So somewhere you create a new cuboid object.

    cuboid* inital = new cuboid(xloop, yloop, zloop, count);

    you have to do

    delete initial;
    initial = NULL;

    at some point.

    If you are creating and destroying the object in just one function then you can do

    cuboid initial(xloop, yloop, zloop, count);

    and not bother with the delete at all.

    Tendofan


  • Closed Accounts Posts: 222 ✭✭The Second


    cheers :D


Advertisement