Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

class conversion with c++

  • 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, Registered Users 2 Posts: 4,127 ✭✭✭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