Jump to content
  • Advertisement
Sign in to follow this  
Scroyall

Class storage size

This topic is 4831 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

I have a problem with one of my C++ programs...so I hope someone can help me! I want to create a dynamic array of a custom class, in this case, 'physics::vector'. It has the members 'float x, y' and some constructors and operator overloads. When I try to create a dynamic array, in either of the two methods I have tried vector<physics::vector> points; or physics::vector* points[]; I get the error that 'storage size of physics::vector isn't known'. Can I define the storage size, or something else, or is it simply not possible? Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Are you sure the actual class definition is visible from the point that you are trying to declare the arrays? That sounds like an error you get when you only have a forward declaration.

Share this post


Link to post
Share on other sites
That's a weird problem.

Some tips:

- Use the (compile time) sizeof() operator to figure out the size. Printf it.
- Virtual functions add data (the virtual table) to your class.
- Probably the most relevant: use std::vector (it might collide with physics::vector?)

Share this post


Link to post
Share on other sites
The class definition is split into a .ccp and a header, and included into the source file where I am trying to make the array...is that right?

The header lays out the class, then the .cpp defines everything.

Mind you...I'm *very* new to C++, so I'm a little confused after switching from VB... :D

*edit

Didn't see your post Jan... my vector class isn't interfering, so it can't be that. Also, say I did use sizeof() to get the class size...how would I let the compiler know that size to avoid the error?

Share this post


Link to post
Share on other sites
Quote:
Original post by Scroyall
The class definition is split into a .ccp and a header, and included into the source file where I am trying to make the array...is that right?

The header lays out the class, then the .cpp defines everything.


That could be it.

If it's only defined as "class vector;", then the compiler is aware that the class exists, but it has no information about the size of it.
If it's defined in the header as this:

class vector {
float x, y;
... And whatever function prototypes you need for the class ...
}

then the compiler knows the size of the class. The trick is that it doesn't have access to the other cpp file when compiling.

The sizeof() thing mentioned above was only to let you read the size, to see if there's anything weird going on. You can't use that to tell the compiler the size of the class.

Share this post


Link to post
Share on other sites
*edit. Scratch that, still doesn't work. :(

I'm #including only the .h file...is that right? Or do I need to include the .cpp as well? That's about the only thing I can think of.

Share this post


Link to post
Share on other sites
You may need to show the contents of your header. Also, are you sure you don't have any circular inclusions?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!