Re: size of class same as base class if no new data members?
guy.tristram@gmail.com wrote:
Can I assume that if I have:
class A
{
/* a few built in types */
};
class B : public A
{
private:
//prevent copy and assignment
B( B const & );
operator=( B const & );
};
instances of class A will be the same size as instances of class B?
More particularly, if I have:
std::vector< A > v(2);
B *b = static_cast< B * >( &v[0] );
++b;
will b point to the second element of v? Does the standard offer any
guarantees?
Murphy's Law guarantees that it will work on your development machine, but
fail elsewhere. Don't use hacks like this. They cost too much in
reliability, and their gains don't offset this near enough. Find a clean
solution.
Victor Bazarov wrote:
guy.tristram@gmail.com wrote:
Can I assume that if I have:
class A
{
/* a few built in types */
};
You mean, there are data members here? 'cause your class looks like it
has no data members at all...
He meant that showing a few members of built-in types wouldn't be
practical in a Usenet posting:
class A
{
int i;
double d;
};
See? Way too impractical. :)