class word in parameters

Mar 6, 2015 at 3:16pm
Hello,

Could you please tell me why put the "class" word in front of Visitor* in the code below and why not just put virtual void accept(Visitor*)=0;
?

Thank you in advance

1
2
3
4
5
class Color
{
	public:
		virtual void accept(class Visitor*)=0;
};
Mar 6, 2015 at 3:22pm
You wouldn't do this.
Where is this "example" from?
I think in C you might be required to do this with a struct, but certainly not in c++.
Last edited on Mar 6, 2015 at 3:25pm
Mar 6, 2015 at 4:22pm
It is optional in C++, as it is a carry-over from C - C++ treats the struct and class keywords the same (aside from default privacy settings). Typically you might see code like this from a C developer transitioning into C++. It may also be a shortcut syntax for avoiding forward declaration (though that's just excessively lazy):
http://ideone.com/2Zk6oK
Topic archived. No new replies allowed.