James Kanze
10/1/2008 9:23:00 AM
On Sep 30, 10:51 pm, "David" <no...@nowhere.com> wrote:
> Yeah, basically that... Would this work:
> struct {
> int a,b,c,d,e,f,g,h,i,j;
> CMyClass C;
> } MyStruct;
> MyStruct A={CMyClass(whatever))};
> or would I have to always deal with a through j?
Agglomerate initialization is always in order within a single
object. What you could do is:
struct MyStruct {
struct { int a, b, c, d, e, f, g, h, i, j ; } intData ;
MyClass classData ;
} ;
MyStruct a = { {}, MyClass( whatever ) } ;
(I'd definitely drop the C in front of the class name. It's
typically an indication that the class is part of MFC.)
> How about:
> struct {
> int a,b,c,d,e,f,g,h,i,j;
> CMyClass C;
> void Init(void) {
> a=b=c=d=e=f=g=h=i=j=0;
> C(whatever)
> }
> } MyStruct;
First, that's
struct MyStruct { ... } ;
The name of the type comes immediately after the class key (one
of the keywords class, struct or union). What you've written
defines a variable MyStruct with an anonymous class type.
And you're generally better off using an initializer list in the
constructor:
MyClass::MyClass()
: a( 0 )
, b( 0 )
// ...
, C( whatever )
{
}
I'd suggest that you acquire a good C++ introductory text, and
read it. You really do need to know about constructors, etc.,
if you're going to use C++.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34