Why isn't my static member function recognised across assemblies?
I have a helper assembly which includes a function to identify object types:
namespace Util
{
using namespace System;
public ref class CastingHelpers
{
public:
template < class T, cl开发者_运维技巧ass U >
static System::Boolean isinst(U u);
static bool Test() {return true;}
};
}
...but for some reason, when I try and use it in a gui application which references the assembly:
Util::CastingHelpers::Test();
Util::CastingHelpers::isinst<SomeClass^>(someInstance);
..gives me an error:
2>.\DataProcessor.cpp(161) : error C2039: 'isinst' : is not a member of 'Util::CastingHelpers'
Note that test works fine. Is this something to do with the fact that isinst uses generics?
You are not creating a generic function, you are creating a C++ template function which is not exported from the assembly.
Use the keyword generic
instead of template
to create .NET generic types and methods.
The template method is only visible by code that #includes its declaration.
精彩评论