• Advertisement

Archived

This topic is now archived and is closed to further replies.

Initializing array member objects in c++

This topic is 4996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have somewhat of a problem and no idea how this is done or even if it's possible. But this is what I have:
class Plane3
{
   public:
      inline
         Plane3(const Point3 &p0, 
                const Point3 &p1,
                const Point3 &p2);
      ...

   private:
      Point3 mP[3];
};
  
What I want to do is initialize the mP array member in the constructor. Something like this:
inline 
   Plane3:: Plane3(const Point3 &p0,
                  const Point3 &p1,
                  const Point3 &p2)
      : mP[0](p0), mP[1](p1), mP[2](p2)
   {
   }
  
Of course this isn't valid code so my question is what syntax can you use when initializing array member objects when constructing an object? Having three separate member variables and initializing them isn't acceptable, I need it to be an array. Thanks! *edit* Damn smilies. [edited by - asp_ on June 10, 2004 5:51:47 AM]

Share this post


Link to post
Share on other sites
Advertisement
there are special tags you can use on this forum that format code properly.

Anyway you can''t program like that.

Understand that:

Point3 mP[3];

... is just declaring a pointer to an array, not the array itself.

you have to actually create the array with a new Point3[3] to allocate the memory actually used for the array. and importantly in the destructor using delete [] mP; rather then just delete mp;

I can see you are trying to be smart and do it in the initaliser list, which is admirable but also wrong - because at that stage the memory hasn''t been allocated for the array yet.

so first
mp = new Point3[3];

to allocate the memory.

then you just do

mp[0] = p0;
...
...


Also be warey of optimising before you know there is a bottleneck. Get it done, if there''s a bottleneck you can find it and deal with it later.
inline is subjective to the compiler anyway - unless you specifically force it to inline it may disregard that. It may also inline stuff you haven''t asked it too... and it will do that itself if it knows there will be a speed increase.

Careful with mixing references and consts and things like that too. Do you really want to be sending over a reference to an object rather then a pointer to it? There is a difference when it comes to assignment.

Using a reference and setting a reference like that will invoke a copy contructor or overloaded assignment constructor, and create a new copy of the object in the array.

Using a pointer would just copy over the pointer... but then you have to decide who gets control of the lifetime of Point3... so that it gets disposed of properly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
paulsdsrubbish,
Thanks for the reply. I think you assumed I knew less C++ than I do since my question was syntactical =) However it is imperative that the default constructors are avoided. Thanks for the suggestions though. Maybe I''m misstaken in my replies, if so, please correct me =)

quote:

there are special tags you can use on this forum that format code properly.


And they were used =) Maybe I should have used the source tags instead of the code ones but I used them for readability.

quote:

Point3 mP[3];

... is just declaring a pointer to an array, not the array itself.


Actually that seems wrong to me. The default constructors are run thus the array is fully declared. I think the standard guarantees that each member variable be available and available in the order declared, once the constructor body is run. Pointers would not cause the constructors to be executed.

quote:

I can see you are trying to be smart and do it in the initaliser list, which is admirable but also wrong


Well most code I see initializer lists are used extensively in order to avoid the extra call to the default constructor. Then again most code I see may be wrong.

quote:

so first
mp = new Point3[3];


No thanks. I don''t want it on the heap. Nor do I want the default constructors to run. more correct would be:
mP = new Point3[] = { Point3(...), Point3(...), Point3(...) };
But that still leaves the heap issue. Since I''m using objects required by the processor to be 16-byte aligned, allocating on the heap is somewhat expensive not to mention it should generally be avoided in code used as often as my primitives are.

quote:

Also be warey of optimising before you know there is a bottleneck. Get it done, if there''s a bottleneck you can find it and deal with it later.


The problem is these are base objects and are getting constructed/destroyed all the time. Of course if the default constructor is empty the call will be optimised away.

I''m starting to believe there is no way to do what I want unless I use a std::vector for my array but that''s out of the question. The only way to solve this seems to be to separate the array member mP into 3 variables mP0, mP1, mP2. This is exactly what I wanted to avoid. Anyone who knows the best way to solve the issue? Hopefully I''m not being a total moron =)

Share this post


Link to post
Share on other sites
quote:
Original post by paulsdsrubbish
Understand that:

Point3 mP[3];

... is just declaring a pointer to an array, not the array itself.

Er, no, it''s a statically allocated array. What are you talking about?

quote:
you have to actually create the array with a new Point3[3] to allocate the memory actually used for the array. and importantly in the destructor using delete [] mP; rather then just delete mp;

This would be true if it were a dynamically allocated array (Point3*), which it isn''t.

Share this post


Link to post
Share on other sites
asp_, you may consider creating an ambiguous union inside your class to remedy the problem. Here, let me whip up what I mean.


class Plane3
{
public:
inline Plane3( const Point3 &p0, const Point3 &p1, const Point3 &p2 );

private:

union
{
Point3 m_rgPoints[ 3 ];
struct
{
Point3 m_P0, m_P1, m_P2;
};
};
};

inline Plane3::Plane3( const Point3 &p0, const Point3 &p1, const Point3 &p2 ): m_P0( p0 ), m_P1( p1 ), m_P2( p2 ) { }


This way you can have an array 'interface' to your Point3 data and still be able to initialize the data in the constructor.

[edited by - MikeMJH on June 10, 2004 4:11:00 PM]

Share this post


Link to post
Share on other sites
MikeMJH,
That was beautiful. But unfortunatley it bails with error C2621 which says:

member 'identifier' of union 'union' has copy constructor
A union member cannot have a copy constructor.

So that would kind of kill the purpose of the entire thing since I HAVE to have a copy constructor. I'm using MS Visual C++ 7.1 btw, just in case it's another annoying standard non-compliance thing.

*edit*
Added MSVC version.

[edited by - asp_ on June 10, 2004 4:27:05 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by asp_
MikeMJH,
That was beautiful. But unfortunatley it bails with error C2621 which says:

member 'identifier' of union 'union' has copy constructor
A union member cannot have a copy constructor.

So that would kind of kill the purpose of the entire thing since I HAVE to have a copy constructor. I'm using MS Visual C++ 7.1 btw, just in case it's another annoying standard non-compliance thing.

*edit*
Added MSVC version.

[edited by - asp_ on June 10, 2004 4:27:05 PM]


Let me just write up a quick test and see if GCC gives me a similar error.

Yeah, I do. So looks like that solution is out. :-/

[edited by - MikeMJH on June 10, 2004 4:57:33 PM]

Share this post


Link to post
Share on other sites
why does it have to be an array?

from the looks of things you''re hardcoding the size of the array so just split it into three Point3 objects and initialise them in the initialiser list.

if you really need array access you could declare an array of 3 pointers to Point3 objects and access them through that for loops, whatever.

You basically have the following options (there are probably more, but it''s early):
1) leave the code as it is and pay for the default constructor
2) make an array of heap objects
3) use a vector of objects
4) see above

BTW don''t listen to paulsdsrubbish, I think he thinks you''re using java or something!!

"That''s not a bug, it''s a feature!"
--me

Share this post


Link to post
Share on other sites
ChaosEngine,
quote:

why does it have to be an array?


It doesn''t HAVE to be. I could have three member variables but that would prevent me from accessing it like an array. Of course I could assume that they will be thighly packed and just take the pointer of the first member variable and use that as the base address of the array but that doesn''t feel like solid coding.

quote:

from the looks of things you''re hardcoding the size of the array so just split it into three Point3 objects and initialise them in the initialiser list.


No.

quote:

if you really need array access you could declare an array of 3 pointers to Point3 objects and access them through that for loops, whatever.


Pointers = needs to be allocated with new which is too slow for what I want. Using loops when accessing the elements would definitely kill my performance and I see no reason why I''d need to do that even with pointers.

quote:

You basically have the following options (there are probably more, but it''s early):
1) leave the code as it is and pay for the default constructor
2) make an array of heap objects
3) use a vector of objects
4) see above


1) Yeah that is an option and is what I''m currently using. But I have several classes like this and even though it''s not THAT costly, it''s not free either.
2) Not an option. Would be slower than option 1.
3) Even slower than option 2.
4) Error: C4717

I''m going to be using option 1 until Stroustrup appears in a vision and tells me what the true path is. Thanks for the replies

Share this post


Link to post
Share on other sites
quote:
Original post by asp_
It doesn't HAVE to be. I could have three member variables but that would prevent me from accessing it like an array. Of course I could assume that they will be thighly packed and just take the pointer of the first member variable and use that as the base address of the array but that doesn't feel like solid coding.


Class-static array of pointers to your member variables


class Foo
{
Bar a, b, c;

// array of 3 pointers to Bar members of Foo
static Bar Foo::*array[3];

public:
Bar& operator[](size_t idx)
{ return this->*array[idx]; }

const Bar& operator[](size_t idx) const
{ return this->*array[idx]; }
};

// Parse this
Bar Foo::*Foo::array[3] = { &Foo::a, &Foo::b, &Foo::c };



“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan


[edited by - Fruny on June 11, 2004 2:57:48 AM]

Share this post


Link to post
Share on other sites
Okay, first of all, stop everything you are doing. You don't need to be optimizing like this, expecially with that compiler. The inline keyword doesn't do anything , by the way, in any recent compiler.

How do you know you need to optimize? Was your old code too slow?

[edited by - thedevdan on June 11, 2004 3:21:00 AM]

[edited by - thedevdan on June 11, 2004 3:21:14 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by thedevdan
Okay, first of all, stop everything you are doing. You don''t need to be optimizing like this, expecially with that compiler.

it does seem a little premature.

quote:
The inline keyword doesn''t do anything , by the way, in any recent compiler.


Cough. Splutter... you are most certainly making that up.

quote:
How do you know you need to optimize? Was your old code too slow?


good point.

Share this post


Link to post
Share on other sites
thedevdan,

quote:

Okay, first of all, stop everything you are doing. You don''t need to be optimizing like this, expecially with that compiler. The inline keyword doesn''t do anything , by the way, in any recent compiler.

How do you know you need to optimize? Was your old code too slow?


This isn''t optimizing. My SSE based classes are optimized. This is just writing solid code by using common sense so that you make sure to avoid misstakes the compiler might make. The way I''m doing it I know what will happen as it''s specified by the standard. The way you want me to do it I''ll be praying for all compilers to all be heavily optimizing and similar in implementation. I prefer my way and it takes me a second or so more to write the code my way
I''ve pretty much gone thru my entire coding life hearing: "Premature optimization is the root of evil.". I don''t optimize prematurely (ahem). What I do is design algorithmic optimizations, write solid code and then profile what needs to be optimized. In this case this is just a matter of solid code and the fact that this is something I need. It must be indexable like an array and constructed without the default constructor.
By the way, the inline keyword actually causes some functions to be considered and inlined which wouldn''t normally be so. It''s a hint not a command. Then again you probably knew this

Fruny,
Thanks for the suggestion! So you take a static array, fill it with the addresses of the members and then dereference the pointers inside, hehe. Clever Kind of reminds me of a manual jump table but for variables. However, when the class is constructed wont the array have to be filled with the data, causing three assignments which wouldn''t otherwise be there? The problem is I to have as close to 0 unnecessary overhead as possible. Cool suggestion though.

Anyone have a good reason for why MikeMJH''s suggestion isn''t allowed?

quoting myself:
quote:

Of course I could assume that they will be thighly packed and just take the pointer of the first member variable and use that as the base address of the array but that doesn''t feel like solid coding.


Is there a reason, other than alignment, why they wouldn''t be tightly packed if in a struct? Just thinking of the MikeMJH''s suggestion which would essentially be the same:


class Plane3
{
public:
inline
Plane3(const Point3 &p0,
const Point3 &p1,
const Point3 &p2)
: mP0(p0), mP1(p1), mP2(p2)
{
};

inline Point3 &
operator [](int el);

private:
// Hopefully tightly packed? Yes I''m from an asm and C

// background ;) If the compiler chooses a padding in

// order to accomodate alignment we''re screwed. Fortunatley

// Point3''s are 16-byte aligned and fits perfectly ;). No this

// isn''t ugly, it''s much worse than that. Hideous? It does the

// work though and would work in any case where the

// sizeof(element) % 4 == 0 since 4 byte alignment is what you

// usually see and would yield a distance of 0.

// Does the struct even effect distance between member

// objects?

struct
{
Point3 p0;
Point3 p1;
Point3 p2;
};
};

inline Point3 &
Plane3::operator[](int el)
{
assert(el < 3);
return (&mP0)[el];
};



Maybe that''s just plain stupid and going way overboard...

Share this post


Link to post
Share on other sites
quote:
However, when the class is constructed wont the array have to be filled with the data, causing three assignments which wouldn''t otherwise be there? The problem is I to have as close to 0 unnecessary overhead as possible.


It''s a static array.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
*DISCLAIMER - all code provided after 3PM and before 10AM may be complete bollocks, and no quality is assured. Any code produced on Fridays in particular is "before the weekend" quality code and may contain alcohol inspired functions and comments. Author has recently been having to do way too much Java and C# for his own good*

Yeah sorry everyone about the array thing.

Pretty sure when you pass things using func( foo array[] ) that you pretty much get a reference because arrays are passed by "simulated call-by-reference". Arrays don't tend to be put on the stack.

Anyway with my tail between my legs I've tried for a few minutes to do the initalisation in an initaliser list - and I get this:
error C2536: 'Plane3::arPoints' : cannot specify explicit initializer for arrays

And I can't do it with dynamic arrays either
error C2538: new : cannot specify initializer for arrays

So I think you'll just have to do it in the constructor body rather then the list.

At least I was right about the inline stuff... I think.
[EDIT: Well it depends on the compiler and compiler settings - in Visual C++ 6 you can set it to create larger code for speed, or smaller code for size - which can override your inline statements]

Anyway I'm going to have a very strong cup of coffee, sit at the back of the class with a dunce hat on and think about what I've done. ;-)

[edited by - paulsdsrubbish on June 11, 2004 5:01:41 AM]

Share this post


Link to post
Share on other sites
Fruny,
quote:

It's a static array.


Yeah I noticed that The problem is that the members in the class aren't occupying the same memory space from class instance to instance. Thus the array would have to be refilled with the memory address of each of the member variables every time the class is instatiated. Seems to me like one instance of your Plane3 class would overwrite the address of the previous instance making having several Plane3 instances impossible. Am I being a total retard?? ;P

paulsdsrubbish,
quote:

And I can't do it with dynamic arrays either
error C2538: new : cannot specify initializer for arrays


I think I provided an example with dynamic array initialization previously. There's no reason to initialize a dynamic array in the initializer list of a constructor though.

Thanks for the help everyone is providing even though no one seems to agree with what I'm doing or rather trying to do

*edit*
Spelling.

[edited by - asp_ on June 11, 2004 5:19:37 AM]

Share this post


Link to post
Share on other sites
The problem is that the members in the class aren't occupying the same memory space from class instance to instance.

That's not a problem.

Thus the array would have to be refilled with the memory address of each of the member variables every time the class is instatiated. Seems to me like one instance of your Plane3 class would overwrite the address of the previous instance making having several Plane3 instances impossible.

No. Look harder at the code I've written. It doesn't quite work the way you think it works. If you pay close attention, I believe you'll learn something new

Am I being a total retard?? ;P

*shrug*

Edit - hint: there is a huge difference between the Bar* and Bar Foo::* types.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan


[edited by - Fruny on June 11, 2004 5:32:25 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by asp_
Fruny,
quote:

It''s a static array.


Yeah I noticed that The problem is that the members in the class aren''t occupying the same memory space from class instance to instance. Thus the array would have to be refilled with the memory address of each of the member variables every time the class is instatiated. Seems to me like one instance of your Plane3 class would overwrite the address of the previous instance making having several Plane3 instances impossible. Am I being a total retard?? ;P




The array doesn''t need to be refilled for every class instance. The array is filled with pointers to members, which is different from standard pointers. Hence the strange this->* notation. It might help if you considered the pointers to members to be offsets into the class (though that''s not an entirely accurate description).

Share this post


Link to post
Share on other sites
SiCrane,
Ahh I see what it does now.

Fruny,
I guess your solution is the way to go then Thanks! Tried it out and it works excellent. As I said previously, clever solution


Thanks everyone.

Share this post


Link to post
Share on other sites
The reason that MikeMJH''s solution doesn''t work is because, as the error says, members of a union can''t have default constructors. Think about it - if you had:

union
{
Foo foo;
Bar bar;
};
and Foo and Bar had their own constructors that did different things, what would happen? They would both be trying to do stuff with the same memory, and the order they''d get constructed in would be undefined also.

Share this post


Link to post
Share on other sites
Aprosenf,
Actually it was the copy constructor the compiler didn't like. But I guess the issues would come from the fact that the objects are sharing memory space. I just don't see why it's the copy constructor which isn't allowed. Then again I might be as blind as I was when I read Fruny's solution.

*edit*
Spelling.

[edited by - asp_ on June 11, 2004 12:08:57 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by asp_
I just don''t see why it''s the copy constructor which isn''t allowed. Then again I might be as blind as I was when I read Fruny''s solution.



union broken
{
Foo foo;
Bar bar;
};

broken a;
broken b = a;


Am I supposed to construct the Foo member or the Bar member?


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
Yeah Fruny''s suggestion generates excellent code for me with no overhead at runtime. If you''re really interested I did run some tests. The code I used is below. You can try different variations of it if you''re actually interested.


#include <cstdio>

class Point3
{
public:
inline
Point3()
{
mP[0] = 0.0f;
mP[1] = 0.0f;
mP[2] = 0.0f;
};

inline
Point3(const Point3 &p)
{
mP[0] = p.mP[0];
mP[1] = p.mP[1];
mP[2] = p.mP[2];
};

inline
Point3(float x, float y, float z)
{
mP[0] = x;
mP[1] = y;
mP[2] = z;
};

inline void
operator =(const Point3 &p)
{
mP[0] = p.mP[0];
mP[1] = p.mP[1];
mP[2] = p.mP[2];
};

inline void
print()
const
{
printf("%f:%f:%f", mP[0], mP[1], mP[2]);
};

private:
float mP[3];
};

class Plane3b
{
public:
inline
Plane3b(const Point3 &p0,
const Point3 &p1,
const Point3 &p2)
{
mP[0] = p0;
mP[1] = p1;
mP[2] = p2;
};

void
print()
const
{
printf("P0:");
mP[0].print();
printf(", P1:");
mP[1].print();
printf(", P2:");
mP[2].print();
};

private:
Point3 mP[3];
};

class Plane3a
{
public:
inline
Plane3a(const Point3 &p0,
const Point3 &p1,
const Point3 &p2)
: mP0(p0), mP1(p1), mP2(p2)
{
};

inline Point3 &
operator[](size_t idx)
{
return this->*mArr[idx];
};

const Point3&
operator[](size_t idx) const
{
return this->*mArr[idx];
};

void
print()
const
{
printf("P0:");
mP0.print();
printf(", P1:");
mP1.print();
printf(", P2:");
mP2.print();
};
private:
static Point3 Plane3a::*mArr[3];
Point3 mP0;
Point3 mP1;
Point3 mP2;
};

Point3 Plane3a::*Plane3a::mArr[3] = { &Plane3a::mP0, &Plane3a::mP1, &Plane3a::mP2 };

int main()
{
Plane3a p(Point3(1.0f, 2.0f, 3.0f),
Point3(4.0f, 5.0f, 6.0f),
Point3(7.0f, 8.0f, 9.0f));

p.print();

}


And here''s my summary of the code MSVC 7.1 generates in release build.


////////////////////////////////////////////////////////////////////////////

// ARRAY INITIALIZER LIST "HACK", EMPTY MEMBER DEFAULT CONSTRUCTOR (PLANE3A)

////////////////////////////////////////////////////////////////////////////

// ENTRY POINT

00401090 >/$ 83EC 24 SUB ESP,24
00401093 |. 8D4C24 00 LEA ECX,DWORD PTR SS:[ESP]
00401097 |. C74424 00 0000803F MOV DWORD PTR SS:[ESP],3F800000
0040109F |. C74424 04 00000040 MOV DWORD PTR SS:[ESP+4],40000000
004010A7 |. C74424 08 00004040 MOV DWORD PTR SS:[ESP+8],40400000
004010AF |. C74424 0C 00008040 MOV DWORD PTR SS:[ESP+C],40800000
004010B7 |. C74424 10 0000A040 MOV DWORD PTR SS:[ESP+10],40A00000
004010BF |. C74424 14 0000C040 MOV DWORD PTR SS:[ESP+14],40C00000
004010C7 |. C74424 18 0000E040 MOV DWORD PTR SS:[ESP+18],40E00000
004010CF |. C74424 1C 00000041 MOV DWORD PTR SS:[ESP+1C],41000000
004010D7 |. C74424 20 00001041 MOV DWORD PTR SS:[ESP+20],41100000
// CALL PLANE3::PRINT()

004010DF |. E8 1CFFFFFF CALL fruny.00401000
004010E4 |. 33C0 XOR EAX,EAX
004010E6 |. 83C4 24 ADD ESP,24
004010E9 \. C3 RETN

////////////////////////////////////////////////////////////////////////////

// COPY OPERATOR, EMPTY MEMBER DEFAULT CONSTRUCTOR (PLANE3B)

////////////////////////////////////////////////////////////////////////////''

// ENTRY POINT

00401090 >/$ 83EC 24 SUB ESP,24
00401093 |. 8D4C24 00 LEA ECX,DWORD PTR SS:[ESP]
00401097 |. C74424 00 0000803F MOV DWORD PTR SS:[ESP],3F800000
0040109F |. C74424 04 00000040 MOV DWORD PTR SS:[ESP+4],40000000
004010A7 |. C74424 08 00004040 MOV DWORD PTR SS:[ESP+8],40400000
004010AF |. C74424 0C 00008040 MOV DWORD PTR SS:[ESP+C],40800000
004010B7 |. C74424 10 0000A040 MOV DWORD PTR SS:[ESP+10],40A00000
004010BF |. C74424 14 0000C040 MOV DWORD PTR SS:[ESP+14],40C00000
004010C7 |. C74424 18 0000E040 MOV DWORD PTR SS:[ESP+18],40E00000
004010CF |. C74424 1C 00000041 MOV DWORD PTR SS:[ESP+1C],41000000
004010D7 |. C74424 20 00001041 MOV DWORD PTR SS:[ESP+20],41100000
// CALL PLANE3::PRINT()

004010DF |. E8 1CFFFFFF CALL fruny.00401000
004010E4 |. 33C0 XOR EAX,EAX
004010E6 |. 83C4 24 ADD ESP,24
004010E9 \. C3 RETN

////////////////////////////////////////////////////////////////////////////

// COPY OPERATOR, MEMBER DEFAULT CONSTRUCTOR SETS POINT TO 0.0f, 0.0f, 0.0f

// (PLANE3B)

////////////////////////////////////////////////////////////////////////////

// PLANE3::PLANE3()

00401090 /$ 8BC1 MOV EAX,ECX
00401092 |. 56 PUSH ESI
00401093 |. 8D70 08 LEA ESI,DWORD PTR DS:[EAX+8]
00401096 |. 57 PUSH EDI
00401097 |. 8BCE MOV ECX,ESI
00401099 |. BA 03000000 MOV EDX,3
0040109E |. 33FF XOR EDI,EDI
004010A0 |> 8979 F8 MOV DWORD PTR DS:[ECX-8],EDI
004010A3 |. 8979 FC MOV DWORD PTR DS:[ECX-4],EDI
004010A6 |. 8939 MOV DWORD PTR DS:[ECX],EDI
004010A8 |. 83C1 0C ADD ECX,0C
004010AB |. 4A DEC EDX
004010AC |.^75 F2 JNZ SHORT fruny.004010A0
004010AE |. 8B4C24 0C MOV ECX,DWORD PTR SS:[ESP+C]
004010B2 |. 8B11 MOV EDX,DWORD PTR DS:[ECX]
004010B4 |. 8910 MOV DWORD PTR DS:[EAX],EDX
004010B6 |. 8B51 04 MOV EDX,DWORD PTR DS:[ECX+4]
004010B9 |. 8950 04 MOV DWORD PTR DS:[EAX+4],EDX
004010BC |. 8B49 08 MOV ECX,DWORD PTR DS:[ECX+8]
004010BF |. 890E MOV DWORD PTR DS:[ESI],ECX
004010C1 |. 8B4C24 10 MOV ECX,DWORD PTR SS:[ESP+10]
004010C5 |. 8B11 MOV EDX,DWORD PTR DS:[ECX]
004010C7 |. 8950 0C MOV DWORD PTR DS:[EAX+C],EDX
004010CA |. 8B51 04 MOV EDX,DWORD PTR DS:[ECX+4]
004010CD |. 8950 10 MOV DWORD PTR DS:[EAX+10],EDX
004010D0 |. 8B49 08 MOV ECX,DWORD PTR DS:[ECX+8]
004010D3 |. 8948 14 MOV DWORD PTR DS:[EAX+14],ECX
004010D6 |. 8B4C24 14 MOV ECX,DWORD PTR SS:[ESP+14]
004010DA |. 8B11 MOV EDX,DWORD PTR DS:[ECX]
004010DC |. 8950 18 MOV DWORD PTR DS:[EAX+18],EDX
004010DF |. 8B51 04 MOV EDX,DWORD PTR DS:[ECX+4]
004010E2 |. 8950 1C MOV DWORD PTR DS:[EAX+1C],EDX
004010E5 |. 8B49 08 MOV ECX,DWORD PTR DS:[ECX+8]
004010E8 |. 5F POP EDI
004010E9 |. 8948 20 MOV DWORD PTR DS:[EAX+20],ECX
004010EC |. 5E POP ESI
004010ED \. C2 0C00 RETN 0C

// ENTRY POINT

004010F0 >/$ 83EC 48 SUB ESP,48
004010F3 |. 8D4424 00 LEA EAX,DWORD PTR SS:[ESP]
004010F7 |. 50 PUSH EAX
004010F8 |. 8D4C24 10 LEA ECX,DWORD PTR SS:[ESP+10]
004010FC |. 51 PUSH ECX
004010FD |. 8D5424 20 LEA EDX,DWORD PTR SS:[ESP+20]
00401101 |. 52 PUSH EDX
00401102 |. 8D4C24 30 LEA ECX,DWORD PTR SS:[ESP+30]
00401106 |. C74424 0C 0000E040 MOV DWORD PTR SS:[ESP+C],40E00000
0040110E |. C74424 10 00000041 MOV DWORD PTR SS:[ESP+10],41000000
00401116 |. C74424 14 00001041 MOV DWORD PTR SS:[ESP+14],41100000
0040111E |. C74424 18 00008040 MOV DWORD PTR SS:[ESP+18],40800000
00401126 |. C74424 1C 0000A040 MOV DWORD PTR SS:[ESP+1C],40A00000
0040112E |. C74424 20 0000C040 MOV DWORD PTR SS:[ESP+20],40C00000
00401136 |. C74424 24 0000803F MOV DWORD PTR SS:[ESP+24],3F800000
0040113E |. C74424 28 00000040 MOV DWORD PTR SS:[ESP+28],40000000
00401146 |. C74424 2C 00004040 MOV DWORD PTR SS:[ESP+2C],40400000
// PLANE3::PLANE3()

0040114E |. E8 3DFFFFFF CALL fruny.00401090
00401153 |. 8D4C24 24 LEA ECX,DWORD PTR SS:[ESP+24]
// PLANE3::PRINT()

00401157 |. E8 A4FEFFFF CALL fruny.00401000
0040115C |. 33C0 XOR EAX,EAX
0040115E |. 83C4 48 ADD ESP,48
00401161 \. C3 RETN

////////////////////////////////////////////////////////////////////////////

// ARRAY INITIALIZER LIST "HACK", MEMBER DEFAULT CONSTRUCTOR SETS POINT TO

// 0.0f, 0.0f, 0.0f (PLANE3A)

////////////////////////////////////////////////////////////////////////////

00401090 >/$ 83EC 24 SUB ESP,24
00401093 |. 8D4C24 00 LEA ECX,DWORD PTR SS:[ESP]
00401097 |. C74424 00 0000803F MOV DWORD PTR SS:[ESP],3F800000
0040109F |. C74424 04 00000040 MOV DWORD PTR SS:[ESP+4],40000000
004010A7 |. C74424 08 00004040 MOV DWORD PTR SS:[ESP+8],40400000
004010AF |. C74424 0C 00008040 MOV DWORD PTR SS:[ESP+C],40800000
004010B7 |. C74424 10 0000A040 MOV DWORD PTR SS:[ESP+10],40A00000
004010BF |. C74424 14 0000C040 MOV DWORD PTR SS:[ESP+14],40C00000
004010C7 |. C74424 18 0000E040 MOV DWORD PTR SS:[ESP+18],40E00000
004010CF |. C74424 1C 00000041 MOV DWORD PTR SS:[ESP+1C],41000000
004010D7 |. C74424 20 00001041 MOV DWORD PTR SS:[ESP+20],41100000
004010DF |. E8 1CFFFFFF CALL fruny.00401000
004010E4 |. 33C0 XOR EAX,EAX
004010E6 |. 83C4 24 ADD ESP,24
004010E9 \. C3 RETN


Of course this is a pretty stupid test but it shows me all that I need to know. The fact is Fruny''s suggestion gives me the ability to address the members as an array and avoid the default constructor.

Share this post


Link to post
Share on other sites

  • Advertisement