我有一个托管C++对象
bool Test::TestStringNumber(String^ testData)
{
int len = testData->Length;
if(len > 0) return true;
}
Run Code Online (Sandbox Code Playgroud)
我在C#中使用相同的功能
void Main()
{
Test t = new Test()
t.TestStringNumber(null);
}
Run Code Online (Sandbox Code Playgroud)
但应用程序崩溃.在调试期间,我在C++中观察到它是'未定义的值'
另外我试图用c ++代码中的nullptr测试testData,并使用下面的代码,但仍然崩溃
if( testData == nullptr && String::IsNullOrEmpty( testData ))
Run Code Online (Sandbox Code Playgroud)
*一种方法是捕获C++托管代码中的异常并返回;
这是我声明的界面:
[ServiceContract]
public interface class IShedluer
{
[OperationContract]
array<Object^>^ GetResult(UInt64 taskId);
}
Run Code Online (Sandbox Code Playgroud)
这是尝试实现它的类:
ref class MyShedluer:IShedluer
{
Shedluer ^shedluer;//this is NOT MyShedluer
public:
MyShedluer(void);
array<Object^>^ GetResult(UInt64 taskId)
{
return shedluer->GetResult(taskId);
}
}
Run Code Online (Sandbox Code Playgroud)
当我试图编译这个时,我得到了
Error 15 error C3766: 'MyShedluer' must provide an implementation for
the interface method 'cli::array<Type> ^IShedluer::GetResult(unsigned __int64)'
d:\users\menkaur\documents\visual studio 2010\projects\MyProject\
\kernel\MyShedluer.h 78 1 MyProject.Kernel
Run Code Online (Sandbox Code Playgroud)
我为什么要这个?
关于动态内存分配,'delete'和'dispose'C++运算符之间有什么区别?
在VC++ CLR项目中我有一个类temp,我试图将静态变量temp1设置为5.我得到一个编译错误:
错误32错误LNK2020:未解析的令牌(0A0005FB)"public:static int temp :: temp1"(?temp1 @ temp @@ 2HA)C:\ Users\user100\Documents\Visual Studio 2012\NewProject 32 bit\create min bars from data2 \从数据创建最小条形\从data5.obj创建最小条形
错误33错误LNK2001:未解析的外部符号"public:static int temp :: temp1"(?temp1 @ temp @@ 2HA)C:\ Users\user100\Documents\Visual Studio 2012\NewProject 32位\从data2创建最小栏\从数据创建最小条形\从data5.obj创建最小条形
我该如何解决?
class temp
{
public:
static int temp1;
};
int main(array<System::String ^> ^args)
{
temp::temp1=5;
}
Run Code Online (Sandbox Code Playgroud)