Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualrip-off

Posted 22 January 2013 - 05:08 PM

i wrote a 3d vector class a while ago, been using it ever since without problem, now recently i found out it seems to have the wrong size in bytes
class Vector3 {
public:
    float x;
    float y;
    float z;
    Vector3();
    Vector3(const Vector3 &v);
    Vector3(float xIn, float yIn, float zIn);
    virtual Vector3 operator=(const Vector3 &rhs);
     ...
};
this yields a sizeof() of 16 bytes instead of 12.
by trying around, i found out that it is due to the the operator(s) being virtual (or any virtual method i add, even the destructor)
if i leave out the 'virtual' keyword, the size is correct, but the linker cant resolve the symbols.

any idea how to handle this, or why the use of 'virtual' changes a classes size?

also, pls dont link descriptions to the virtual keyword, i have been through many, and still don't get it =)
thanks in advance,
Tasche

#3rip-off

Posted 22 January 2013 - 05:07 PM

i wrote a 3d vector class a while ago, been using it ever since without problem, now recently i found out it seems to have the wrong size in bytes

class Vector3 {public:    float x;    float y;    float z;    Vector3();    Vector3(const Vector3 &v);    Vector3(float xIn, float yIn, float zIn);    virtual Vector3 operator=(const Vector3 &rhs);     ...};

this yields a sizeof() of 16 bytes instead of 12.
by trying around, i found out that it is due to the the operator(s) being virtual (or any virtual method i add, even the destructor)
if i leave out the 'virtual' keyword, the size is correct, but the linker cant resolve the symbols.

any idea how to handle this, or why the use of 'virtual' changes a classes size?

also, pls dont link descriptions to the virtual keyword, i have been through many, and still don't get it =)
thanks in advance,
Tasche


#2Tasche

Posted 22 January 2013 - 04:56 PM

i wrote a 3d vector class a while ago, been using it ever since without problem, now recently i found out it seems to have the wrong size in bytes

class Vector3 {public:    float x;    float y;    float z;    Vector3();    Vector3(const Vector3 &v);    Vector3(float xIn, float yIn, float zIn);    virtual Vector3 operator=(const Vector3 &rhs);     ...};

this yields a sizeof() of 16 bytes instead of 12.
by trying around, i found out that it is due to the the operator(s) being virtual (or any virtual method i add, even the destructor)
if i leave out the 'virtual' keyword, the size is correct, but the linker cant resolve the symbols.

any idea how to handle this, or why the use of 'virtual' changes a classes size?

also, pls dont link descriptions to the virtual keyword, i have been through many, and still don't get it =)
thanks in advance,
Tasche


#1Tasche

Posted 22 January 2013 - 09:33 AM

i wrote a 3d vector class a while ago, been using it ever since without problem, now recently i found out it seems to have the wrong size in bytes

 

class Vector3 {
public:
    float x;
    float y;
    float z;
    Vector3();
    Vector3(const Vector3 &v);
    Vector3(float xIn, float yIn, float zIn);

    virtual Vector3 operator=(const Vector3 &rhs); 
    ...
};

this yields a sizeof() of 16 bytes instead of 12.

by trying around, i found out that it is due to the the operator(s) being virtual (or any virtual method i add, even the destructor)

if i leave out the 'virtual' keyword, the size is correct, but the linker cant resolve the symbols.

 

any idea how to handle this, or why the use of 'virtual' changes a classes size?

 

also, pls dont link descriptions to the virtual keyword, i have been through many, and still don't get it =)

thanks in advance,

    Tasche


PARTNERS