先学习了一个例子,面向对象的
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
__gc class Animal
{
public:
int legs;
void SetName(String *name)
{ strName = strName->Copy(name); }
String* GetName() { return strName; }
private:
String *strName;
};
int _tmain()
{
// TODO: Please replace the sample code below with your own.
Animal *cat, *dog;
cat = new Animal;
dog = new Animal;
cat->SetName("Cat");
cat->legs = 4;
dog->SetName("Dog");
dog->legs = 4;
Console::WriteLine("Animal 1");
Console::Write("Name: ");
Console::WriteLine(cat->GetName());
Console::Write("Legs: ");
Console::WriteLine(cat->legs);
Console::WriteLine();
Console::WriteLine("Animal 2");
Console::Write("Name: ");
Console::WriteLine(dog->GetName());
Console::Write("Legs: ");
Console::WriteLine(dog->legs);
Console::WriteLine();
return 0;
}
很好的一个例子,用到了托管代码,__gc,要注意的是,调试时,用到了托管代码,所以要在
项目->属性->c/c++选项->常规->编译为托管 选择 程序集支持 (/clr)
就可以了,值得初学者注意
VC++ .NET 2003学习
原创
©著作权归作者所有:来自51CTO博客作者mb5c80f4c73b73a的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
VC++记录
1. 记录时间 2. 报错 解决
#include -
VC++.Net与VC++的区别
VC++.NET是指在托管CLR(公共语言运行库)上建立的VC++程序才叫VC++.NET
VC++ vc++ .net 运行库 公共语言 -
dotcms es 配置文件位置
这是关于object的新api <script> function box(name) { this.name = name; this.age = 26; } var obj = {name:'hanyu',age:26}; var obj1 = Object.create(obj)//根据此对象为
dotcms es 配置文件位置 json javascript ViewUI 数组