I think I've been up too long at this stage.. I think this is a really stupid question:

How do I declare all my objects from main() ?
I have an object 'sun' of the class 'CPlanet' and within that class there is an instance of the class 'CAnimation'. But I would like to instantiate everything from main..
So I want to be able to create (or not create) a 'CAnimation' object within 'sun' from main();

You mean remove it from CPlanet? or leave it there and instantiate another instance of it in main(). I assume the purpose of CAnimation is to make the class rotate on its axis, so removing it from CPlanet would not be a very good idea. If you instantiated an instance of CAnimation directly in main() what would it do? What is it supposed to animate ?

Hi Ancient Dragon,

Sorry if I didn't explain it clearly..
CPlanet is a generic class that instantiates a mass in space. The mass may or may not be animated. In order for it to be animated there must be an object created within CPlanet that makes animation possible. I do not want this object created each time I make a planet, because some of the planets are just red circles...

So if I have created a CPlanet object called planet, can I then create a CAnimation object called animation within that? And can I do this from main?

Something like:

int main ()
{

...
CPlanet planet;
planet.CAnimation animation;
...
return 0;

}

of-course that code doesn't work, but you get what I mean, yeah?

Thanks for your reply :)

you can make CAnimate a pointer

class CPlanet
{
 ...
   CAnimate* m_animateptr;
};

int main()
{
    CPlanet planet;
    planet->m_animateptr = new CAnimate;
}

But you should probably put the code in CPlanet to make it allocate all necessary memory for itself

class CPlanet
{
public:
    CPlanet(bool bNeedAnimate = true)
    {
        if( bNeedAnimate)
            m_animateptr = new CAnimate;
        else
            m_animateptr = NULL;
    }
 ...
   CAnimate* m_animateptr;
};

Yes, the pointer solution is what I'm looking for. :)

The reason I don't want to use the second approach is because I need to pass a lot of additional parameters to the CAnimate object.. so this would mean I need intermediate functions to transpose those parameters from CPlanet to CAnimate.. this would cause my code to bloat a bit I think..

Thanks a lot for the fast reply and sorry for stupid thread... I've been up for a long time now and my mind was going numb :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.