compiling problems

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2003
Posts: 208
Reputation: camelNotation is an unknown quantity at this point 
Solved Threads: 2
camelNotation's Avatar
camelNotation camelNotation is offline Offline
Posting Whiz in Training

compiling problems

 
0
  #1
Nov 24th, 2003
Hello.I am having some problems with my vc++6 compiler.Here is the code:
  1. #include <iostream.h>
  2.  
  3. class SimpleCat
  4. {
  5. public:
  6.  
  7. SimpleCat() { itsAge = 2; } // if I put the definition of the function into the daclaration,that becomes an "inline" function
  8. ~SimpleCat() { } // class destructor
  9. int GetAge() const { return itsAge;}
  10. void SetAge ( int age ) { itsAge = age;}
  11.  
  12. private:
  13. int itsAge;
  14. }; // class declaration ends
  15.  
  16. int main ()
  17. {
  18.  
  19. cout << " generally,to access data members and functions,\n";
  20. cout << " we use the dot (.) operator...\n";
  21. cout << "but here while accessing the Cat object on the free...\n";
  22. 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";
  23. cout << " to access the GetAge member function,I will write (*pRags).GetAge();\n";
  24. cout << " The format is like this: (*nameOfThePointer).nameOfTheFunctionToBeAccessed();\n";
  25. cout << " But,in c++,the operator needed is (->) or ( dash,greater-than)\n";
  26.  
  27. SimpleCat * Frisky = new SimpleCat; // creating simplecat object on the freestore or heap
  28.  
  29. cout << " Frisky is" << Frisky->GetAge() << "years old\n";
  30. Frisky->SetAge(5);
  31. cout << " Frisky is << Frisky->GetAge() << " years old\n";
  32. delete Frisky ;
  33. return 0;
  34. }
  35.  

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
Forum bully
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Solved Threads: 1
Team Colleague
Bob Bob is offline Offline
Team Member

Re: compiling problems

 
0
  #2
Nov 26th, 2003
> 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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC