Hello.I am having some problems with my vc++6 compiler.Here is the code:

#include <iostream.h>

class SimpleCat
{
public:

	SimpleCat() { itsAge = 2; }  // if I put the definition of the function into the daclaration,that becomes an "inline" function
	~SimpleCat() { }              // class destructor
	int GetAge() const { return itsAge;}
	void SetAge ( int age ) { itsAge = age;}
	
private:
	int itsAge;
};                                    // class declaration ends

int main ()
{
  
cout << " generally,to access data members and functions,\n";
  cout << " we use the dot (.) operator...\n"; 
 cout << "but here while accessing the Cat object on the free...\n";
cout << " store,I must dereference(indirectly access from the pointer with * symbol) the pointer and call the dot operator on the object pointed to by the pointer\n";
cout << " to access the GetAge member function,I will write (*pRags).GetAge();\n";
cout << " The format is like this: (*nameOfThePointer).nameOfTheFunctionToBeAccessed();\n";
cout << " But,in c++,the operator needed is (->) or ( dash,greater-than)\n";

SimpleCat * Frisky = new SimpleCat;        // creating simplecat object on the freestore or heap

cout << " Frisky is" << Frisky->GetAge() << "years old\n";
Frisky->SetAge(5);
cout << " Frisky is << Frisky->GetAge() << " years old\n";
delete Frisky ;
return 0;
}

here are the compiling errors,I'm sure it's about calling functions from a cout statement..the cout statements are directly from the book the problem is with the compiler:
________________________________


D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2146: syntax error : missing ';' before identifier 'years'
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2017: illegal escape sequence
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2065: 'years' : undeclared identifier
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2146: syntax error : missing ';' before identifier 'old'
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2001: newline in constant
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2065: 'old' : undeclared identifier
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2146: syntax error : missing ';' before identifier 'n'
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2065: 'n' : undeclared identifier
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(36) : error C2143: syntax error : missing ';' before 'string'
D:\ADOBE\VC++6PROJECTS\accessingmemberdataonheap\memdthp.cpp(37) : error C2143: syntax error : missing ';' before 'delete'
Error executing cl.exe.

memdthp.obj - 10 error(s), 0 warning(s)

tia i'm a n00b

> cout << " Frisky is << Frisky->GetAge() << " years old\n";

This should be:

cout << " Frisky is" << Frisky->GetAge() << " years old\n";

Note the " after the word is.

This article has been dead for over six months. Start a new discussion instead.