![]() |
Some C++ questions
I have a few questions for the C++ gurus here.
What does the ... do in functions? Like here: Code:
void blah(int x, int y, ...); Is it possible to make a pointer off of a class that is inherited by another class, and then use that to point to a different one? Like this: Code:
class theclass |
Re: Some C++ questions
Those are all questions which can be found in any c++ book for sure.
the ... : when you don't know how many parameters you gonna have, printf is a nice example there. virtual functions : when you have such a situation with the class theclass and theotherclass like above, and you have a virtual function in the base class, and you got a pointer like instance, you can call the function in the base class, and in case it is defined in the derived class, that one that was instantiated with your "new" statement, that function will be called, overriding the function from the base class. such sort of behaviour is really useful when you just define an interface of a class and you have some derived classes. then you don't need to reimplement your algorithm for each data type, you can just implement it for this class and its interface. This principle is also the reason for making destructors virtual. when you delete an object where you are not sure of the type, and you delete some pointer to some base class, the topmost destructor will be called as well. without being virtual only the destructors of the class which are 'below' the type of which the pointer was are called. I believe that this stuff isnt something you can really learn by reading, you have to have own projects where you need such mechanisms. just an example from my bot's system to handle entities around it: Code:
Code:
m_LIEntities.push_back(pIEntity = new CInterestingWeapon("weaponbox",-1,false)); Code:
while(Entity = UTIL_FindEntityInSphere(Entity,VOrigin,_ENT_PERC_RADIUS)){ // loop thru entities around here |
Re: Some C++ questions
Oh I get it now. I knew what virtual functions did, that they were made to be overridden, but not that you would use them for pointers.
Anyway, one of the reasons I asked this question is because I remember it from monster plugin: CBaseEntity themonster[x] = new CBarney Now I know how closely related the two are. I need to go find an example for the ... parameter. Thanks for the help! |
All times are GMT +2. The time now is 06:18. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.