注册 登录
编程论坛 VC.NET论坛

弱弱地问一下,托管的C++应用程序?

树上的番茄 发布于 2008-07-16 18:19, 2848 次点击
小弟装得是
找了半天就是没有找到有新建托管得C++应用程序这个项目!
只得建了个 控制台应用程序(.net)
编译有问题!
// 这是使用应用程序向导生成的 VC++
// 应用程序项目的主项目文件。

#include "stdafx.h"
#include <string.h>

#using <mscorlib.dll>
#include <tchar.h>
using namespace System;

 _gc class animal
{
public:
    int legs;
    void SetName(String *Name){strName=Copy(Name);};
    String *GetName(){return strName;};

private:
    String *strName;

};


int _tmain(void)
{
    // TODO: 请用您自己的代码替换下面的示例代码。
    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;
}

e:\My Documents\Visual Studio Projects\animals\animals.cpp(12): error C2143: 语法错误 : 缺少“;”(在“<类头>”的前面)
e:\My Documents\Visual Studio Projects\animals\animals.cpp(12): error C2501: “_gc” : 缺少存储类或类型说明符
e:\My Documents\Visual Studio Projects\animals\animals.cpp(19): error C3265: 无法声明托管“strName”(在非托管“animal”中)



这2个项目有什么差别????

还好 小弟得编译器是不是少了某些东西?
0 回复
1