Author Topic: Problem with compiling  (Read 2294 times)

JimB121

  • Guest
Problem with compiling
« on: May 30, 2009, 08:04:52 am »
When I include the following code in my program it gives an error.

class particle{
     public:
            float size_x;
            float size_y;
            float size_z;
};
particle                  particle_v[100000000];
particle_v[1].size_x = 1;

This should work but for some reason it doesn't work in Code::Blocks.
the error is the following

error: expected constructor, destructor, or type conversion before '.' token

thanks in advance.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem with compiling
« Reply #1 on: May 30, 2009, 09:54:43 am »
Where did the error come from?
Compiler?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

zabzonk

  • Guest
Re: Problem with compiling
« Reply #2 on: May 30, 2009, 09:55:14 am »
Nothing to do with CB - it is not legal C++ code. Move the statement

 particle_v[1].size_x = 1;

into main() or some other function. And if you run it, be prepared for a stack overflow - once again, nothing to do with CB.

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Problem with compiling
« Reply #3 on: May 30, 2009, 10:03:51 am »
once again, nothing to do with CB.

Therefore violating our forum rules.

Topic locked !!!