J
James Thompson
Ok, I am trying to learn C++ .NET, so I went and bought
Visual C++ .NET Step by Step. I started the first project
and I have typed in the code EXACTLY like the book tells
me to. Then when I build the project, I get these errors:
c:\Projects\animals\animals.cpp(13): error C2143: syntax
error : missing ';' before '<class-head>'
c:\Projects\animals\animals.cpp(13): error C2501: '_gc' :
missing storage-class or type specifiers
c:\Projects\animals\animals.cpp(20): error C3265: cannot
declare a managed 'strName' in an unmanaged 'animal'
c:\Projects\animals\animals.cpp(35): error C2143: syntax
error : missing ';' before '.'
Here is my code for the project that I typed exactly from
the book.......can anyone figure out why this would not
run?
// This is the main project file for VC++ application
project
// generated using an Application Wizard.
#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 = strName->Copy(Name);};
String* GetName() {return strName;};
private:
String *strName;
};
int _tmain(void)
{
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();
return 0;
}
Visual C++ .NET Step by Step. I started the first project
and I have typed in the code EXACTLY like the book tells
me to. Then when I build the project, I get these errors:
c:\Projects\animals\animals.cpp(13): error C2143: syntax
error : missing ';' before '<class-head>'
c:\Projects\animals\animals.cpp(13): error C2501: '_gc' :
missing storage-class or type specifiers
c:\Projects\animals\animals.cpp(20): error C3265: cannot
declare a managed 'strName' in an unmanaged 'animal'
c:\Projects\animals\animals.cpp(35): error C2143: syntax
error : missing ';' before '.'
Here is my code for the project that I typed exactly from
the book.......can anyone figure out why this would not
run?
// This is the main project file for VC++ application
project
// generated using an Application Wizard.
#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 = strName->Copy(Name);};
String* GetName() {return strName;};
private:
String *strName;
};
int _tmain(void)
{
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();
return 0;
}