Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++, class as parameter to a method, not template

Tags:

c++

class

So, I came across an interesting method signature that I don't quite understand, it went along the lines of:

void Initialize(std::vector< std::string > & param1, class SomeClassName * p);

what I don't understand is the "class" keyword being used as the parameter, why is it there? Is it necessary to specify or it is purely superficial?

like image 938
ra170 Avatar asked May 14 '10 18:05

ra170


1 Answers

It is a forward declaration of the class. It is the effectively the same as

class SomeClassName;
void Initialize(std::vector< std::string > & param1, SomeClassName * p);

There are many situations in which a forward declaration is useful; there's a whole list of things that you can and can't do with a forward declaration in this answer to another question).

like image 103
James McNellis Avatar answered Oct 19 '22 17:10

James McNellis