G
Gopal-M
I have the problem with sizeof operator I also want to implement a
function that can return size of an object. My problem is as follows..
I have a Base class, say Base and there are many class derived from
it. At a particular point in my application I need the size of the
object pointed to by the base pointer. Eg
Class Base
{
private:
int m_nBaseData;
virtual void Display() = 0;
};
class Dev1: public Base
{
private:
int m_nDev1Data[10];
public:
void Display()
{
/// ……. Code..
}
};
class Dev2: public Base
{
private:
int m_nDev2Data[10];
public:
void Display()
{
/// ……. Code..
}
};
void main()
{
Base* p1 = new Dev1;
Base* p2 = new Dev2;
unsigned int size1 = sizeof(*p1); // LINE # 1
unsigned int size2 = sizeof(*p2); // LINE # 2
}
As the code given above I am getting size as 8 in LINE # 1 and LINE #
2, it is the size of the Base class.
In my application I need the size of the object pointed to by the
pointer. Means, if the base pointer contains the Dev1 obj then i
should some how need the size of the object pointed by Base pointer.
Can any one give me any solution for this.
Gopal.
Lambent Technologies
function that can return size of an object. My problem is as follows..
I have a Base class, say Base and there are many class derived from
it. At a particular point in my application I need the size of the
object pointed to by the base pointer. Eg
Class Base
{
private:
int m_nBaseData;
virtual void Display() = 0;
};
class Dev1: public Base
{
private:
int m_nDev1Data[10];
public:
void Display()
{
/// ……. Code..
}
};
class Dev2: public Base
{
private:
int m_nDev2Data[10];
public:
void Display()
{
/// ……. Code..
}
};
void main()
{
Base* p1 = new Dev1;
Base* p2 = new Dev2;
unsigned int size1 = sizeof(*p1); // LINE # 1
unsigned int size2 = sizeof(*p2); // LINE # 2
}
As the code given above I am getting size as 8 in LINE # 1 and LINE #
2, it is the size of the Base class.
In my application I need the size of the object pointed to by the
pointer. Means, if the base pointer contains the Dev1 obj then i
should some how need the size of the object pointed by Base pointer.
Can any one give me any solution for this.
Gopal.
Lambent Technologies