I'm not so experience with templates, and I've found some usage in my team's code that has me confused.
Let's say I have a base class with the following two typedefs for shared_ptr:
class Foo
{
virtual ~Foo();
virtual void bar() = 0;
};
typedef boost::shared_ptr<Foo> FooPtr1; //this is what i'm used to seeing
typedef boost::shared_ptr<class Foo> FooPtr2; //this is in our codebase
Is there any difference between these typedef's? Is it related to usage with derived classes?
There's no difference.
The syntax class Foo
is supported for consistency with struct Foo
, which in turn is supported for C compatibility. In C a struct
is not a type by itself: the type corresponding to a struct called S
is struct S
, which is usually named via a typedef
. In C++ the typedef
isn't needed, and the syntax is largely irrelevant. I've found it useful for introducing "inline" tag types for template instantiations, like X< whatever, struct X_tag >
, where the tag type is an incomplete type. But that's all.