I’m trying to use Nullable<bool> as a tribool in C++/CLI (seen as bool? in C#). I get this odd error message from the following function declaration:
static IList<Modification^>^ modifications(double mass,
double tolerance,
Nullable<bool> monoisotopic,
Nullable<bool> approved,
Site site,
Position position,
Classification classification,
Nullable<bool> hidden);
I have the proper using statements to bring the types into scope. The error occurs for each use of Nullable:
error C3224: 'System::Nullable' : no overloaded generic class takes '1' generic type arguments
I also tried Nullable<System::Boolean> but get the same error. The error goes away if I use the fully qualified name System::Nullable…but why?!
There are two different
System::Nullables — a non-generic one and a generic one. Your using declaration brings into scope the former, when it is the latter that you actually want to use.Unfortunately, it is a limitation of C++/CLI that one cannot use a using declaration to bring a generic type into scope when there exists another non-generic type with the same name. Your only real options here are to fully qualify the type name or to use a using directive instead of a using declaration (i.e.,
using namespace System;).