Can anyone explain why I get the following errors when compiling the code shown below (and how to fix it)
error C3767:
'ManagedClass::SetString'
: candidate function(s) not accessible e:\Temp\ManagedCpp\ManagedCpp\ManagedCpp.cpp 24 ManagedCpperror C3767:
'ManagedClass::GetString'
: candidate function(s) not accessible e:\Temp\ManagedCpp\ManagedCpp\ManagedCpp.cpp 26 ManagedCpp
I read the following similar question, C++ CLI error C3767: candidate function(s) not accessible which states
I recommend using the managed type
System::String^
instead in all your public API. This also ensures that your library is easily callable from other CLR languages such as c#
Which is exactly what I did (BTW This is a test code used to extract the same compilation error in a much larger mixed mode dll).
(The project is a VS2008 C++/CLI project i.e from Menu select File->New Project->Visual C++->CLR Console Application.)
Thanks for all you help.
using namespace System;
static public ref class ManagedClass
{
static public int SetString(String^ s)
{
str = s;
}
static public String^ GetString()
{
return str;
}
static String^ str ;
};
int main(array<System::String ^> ^args)
{
String^ test ="Here";
ManagedClass::SetString(test);
String^ j= ManagedClass::GetString();
return 0;
}