7,540
社区成员
发帖
与我相关
我的任务
分享
ref class A
{
private:
int i;
static int j;
public:
A()
{
i = 0;
}
void f()
{
System::Console::WriteLine("f been called");
System::Console::WriteLine(j);
//System::Console::WriteLine(i);// exception 了
}
virtual System::String^ ToString () override
{
System::Console::WriteLine("tostring been called");
return "A:";
}
};
int main()
{
A^ a;// = nullptr; // 置空一样
a->f();
System::Console::WriteLine(a->ToString());
}
Class^ a = nullptr;
try
{
gcnew Class();// 这里一时忘了对 a 赋值
a->CallShit();// 函数里头访问 this 指针时异常了
}
#include <iostream>
using namespace std;
int main()
{
cout < <"sorry,I am a new comer,I don't know what's this,but I am studying!" ;
cout < <"jf" < <endl;
cout <<"sorry,there is a wrong just!";
return 0;
}
// liblib.cs
// csc /t:library liblib.cs
public class A
{
public void f()
{
System.Console.WriteLine("f been called");
}
}
class prgram
{
static void Main()
{
A a = null;
a.f(); // 同样一个库函数调用, 这里调用失败
}
}
// caller.cpp
// cl /clr:safe caller.cpp
#using "liblib.dll"
int main()
{
A^ a = nullptr;
a->f();// 而这里调用成功
}