Thread: example from my book wont compile

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    23

    example from my book wont compile

    Hello Im tring to compile an example from my C++ book but its faulting with this error

    Code:
    
    mike@laptop:~/code/C++/chapter_3$ g++ grade_3.cpp -o grade3
    grade_3.cpp:18: error: expected primary-expression before ‘void’
    grade_3.cpp:18: error: ISO C++ forbids declaration of ‘pubilc’ with no type
    grade_3.cpp:18: error: expected ‘;’ before ‘void’
    grade_3.cpp:23: error: expected `;' before ‘string’
    grade_3.cpp: In function ‘int main()’:
    grade_3.cpp:23: error: ‘std::string GradeBook::getCourseName()’ is private
    grade_3.cpp:42: error: within this context
    grade_3.cpp:46: error: ‘class GradeBook’ has no member named ‘setCourseName’
    grade_3.cpp:28: error: ‘void GradeBook::displayMessage()’ is private
    grade_3.cpp:48: error: within this context
    and here is the source

    Code:
    //      GradeBook example
    
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    
    #include <string>
    using std::string;
    using std::getline;
    
    class GradeBook
    {
    
    pubilc:
    
            void setCourseName( string name )
            {
                    courseName = name;
            }
    
            string getCourseName()
            {
                    return courseName;
            }
    
            void displayMessage()
            {
                    cout << "Welcome to the grade book for\n" << getCourseName() << "!" << endl;
            }
    
    private:
            string courseName;
    };
    
    int main()
    {
            string nameOfCourse;
            GradeBook myGradeBook;
    
            cout << "Inital course name is: " << myGradeBook.getCourseName() << endl;
            cout << "\nPlease enter the course name:" << endl;
            getline( cin, nameOfCourse );
            cout << endl;
            myGradeBook.setCourseName( nameOfCourse );
            cout << endl;
            myGradeBook.displayMessage();
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    You spelled 'public' wrong.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    23
    Quote Originally Posted by Tonto
    You spelled 'public' wrong.
    What an ass Im am sorry Its been a really long day for me

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Quote Originally Posted by Mikecore
    What an ass Im am sorry Its been a really long day for me
    We've all been there....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Templates book discussion
    By manutd in forum C++ Programming
    Replies: 38
    Last Post: 01-18-2007, 03:56 PM
  2. Please Help!!!!!
    By princssashes in forum C# Programming
    Replies: 2
    Last Post: 04-05-2006, 08:18 AM
  3. Must read book!
    By RealityFusion in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 07-15-2004, 09:05 PM
  4. Should i get a new reference book?
    By Raison in forum Windows Programming
    Replies: 2
    Last Post: 06-15-2004, 10:43 PM
  5. I"m selling a book...
    By St0rmTroop3er in forum Game Programming
    Replies: 2
    Last Post: 12-13-2003, 01:55 PM