G
guy.tristram
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? My motivation is that I want to be able to grow a vector
of As, but prevent clients from copying them thereafter. I realize
that I am then using As as though they were Bs and I should perhaps
inherit the other way around, making the copy constructor and
assignment operator protected in the client version, then re-
publicizing them in the internal version, but that would mean
explicitly implementing them.
Guy
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? My motivation is that I want to be able to grow a vector
of As, but prevent clients from copying them thereafter. I realize
that I am then using As as though they were Bs and I should perhaps
inherit the other way around, making the copy constructor and
assignment operator protected in the client version, then re-
publicizing them in the internal version, but that would mean
explicitly implementing them.
Guy