I have a class:
class WorkerThread
{
public:
unsigned virtual run()
{
return 0;
}
};
Defined in the header. Now in another class I create an object of this type:
WorkerThread **workerQueue;
Which is actually a pointer to pointer… OK, all good until now.
Now, how should I read this:
workerQueue = new WorkerThread*[maxThreads];
What is the meaning of the * after the ClassName (WorkerThread) and the array format?
It’s an allocation of an array of
WorkerThreadpointers.For instance:
workerQueue[0]is aWorkerThread*, as isWorkerThread[1]andWorkerThread[2].These pointers, currently have not been initialized.
Later you may see something like this:
I will tell you, that all of these raw pointers are just memory leaks waiting to happen unless carefully handled. A preferred method would be to use a
std::vectorto some smart pointer ofWorkerThreadobjects.