A friend and I are working on an ancient C++ codebase. In this code, an array of CDelayEvent pointers is defined as follows
class CDelayEvent* m_pDelayEventList[DEF_MAXDELAYEVENTS];
and various objects in it are allocated in the following way
m_pDelayEventList[i] = new class CDelayEvent;
My question here is the use of the keyword class
in both lines. The code compiles both lines with and without it.
class
keyword do in this context?I could not find anything about this problem because searching for "new class" only finds unrelated articles and questions.
Do you know C? Then you know how a structure is used? And that you need to use the struct
keyword when e.g. declaring a variable of the structure?
In C++ structures and classes are really the same, and C++ made the need for the struct
and class
keywords optional so a structure or a class could be used as a type.
So in your case you can use class CDelayEvent
or just CDelayEvent
, they are semantically the same.