943,922 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6658
  • C++ RSS
Nov 24th, 2003
0

compiling problems

Expand Post »
Hello.I am having some problems with my vc++6 compiler.Here is the code:
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 16
Solved Threads: 2
Posting Whiz in Training
camelNotation is offline Offline
208 posts
since Sep 2003
Nov 26th, 2003
0

Re: compiling problems

> 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.
Bob
Team Colleague
Reputation Points: 15
Solved Threads: 2
Junior Poster
Bob is offline Offline
129 posts
since Feb 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: problem splitting c++ program
Next Thread in C++ Forum Timeline: The difference between functions and templates?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC