Hi ya
Could you help me with this program? The problem is when I run the program and the name of the animal is not displayed.
Thanks! :-)Code:#include "stdafx.h" #include "string.h" #include "conio.h" #using <mscorlib.dll> 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() { animal *Cat, *Dog; Cat = new animal; Dog = new animal; Cat->SetName("Cat"); Dog->SetName("Dog"); Cat->legs = 4; 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(); Console::Write("Press any key to continue..."); getch(); return 0; }




Reply With Quote