Reputation: 1441
I have a generic class written in C++\CLI, which contains a method returning an instance of the generic type parameter:
generic<typename TWidget> public ref class Factory abstract
{
public:
virtual TWidget^ MakeWidget() abstract;
}
My generic type (TWidget
) will be a reference type, and so I wish my method (MakeWidget
) to return an indirection to the type. Compilation fails with the error
error C3229: 'TWidget ^' : indirections on a generic type parameter are not allowed
Surely this is not an unusual scenario; am I mis-understanding something? (entirely possible as I rarely use this language).
Any suggestions as to how I can appease the compiler and achieve the desired result?
Upvotes: 0
Views: 1302
Reputation: 91
Because your TWidget type is already a reference type, and in fact, the compiler will force you to make it so, you can simply define the return of MakeWidget as TWidget.
Upvotes: 2