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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

class conversion with c++

  • 02-12-2003 11:33am
    #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, Registered Users 2 Posts: 4,196 ✭✭✭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, Registered Users 2 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