🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Classes within Classes

Started by
3 comments, last by WitchLord 16 years, 2 months ago
It would be nice if we could created classes inside classes. In the game im making, everything is done using classes. Each npc code is automatically inserted within a class like this:

class SomeNpc
{
  float x;
  float y;
  float depth;
  //Npc code is inserted here
}
But if i wanted to create a boss npc that has projectiles, the npc code would look something like this:


class Projectile
{
  float x;
  float y;
}

Projectile[] projectiles;

void OnCreate()
{
  //add projectiles to array
}

void OnUpdate()
{
  //loop through the projectiles array and check for collisions with
  //players and move the projectiles
}
I cant do it because i cant define a class within another class
Advertisement
What compiler are you using? Nested classes should be possible. IIRC, they automatically get access to the containing class' private members. Still, even if your compiler doesn't support nested classes, I don't see why would that be an obstacle to your implementation (except, maybe, if you are using templates). Just get the class somewhere else.
err, the angelscript compiler lol. The code i showed was angelscript code.
Whoops! I opened the topic from the Recent Threads list, and completely missed the subforum it was posted at. Sorry about that. :)

Have fun!
Declaring classes within classes, will eventually be available in AngelScript as well. For now though, perhaps you can live with declaring all the classes in the global scope.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement