Thread: class error

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    164

    class error

    hi im getting an error while compiling this


    testgrade.cpp
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    #include "grade.h"
    
    int main()
    {
    	GradeBook grade1("CS101	Introduction to Programming in C++", "Manzoor Ahmed");
    	GradeBook grade2("CS102 C++ Data Structures", "Manzoor Ahmed");
    
        cout << grade1.displayMessage();
        cout << grade2.displayMessage();
    
        return 0;
    
    }
    grade.cpp

    Code:
    #include <iostream>
    #include <string>
    #include "grade.h"
    
    using namespace std;
    
    GradeBook::GradeBook(string name, string instName) // constructor
    	{
    		setCourseName(name);
    		setInstrName(instName);
    	}
    
    void GradeBook::setCourseName(string setName)
    	{
    		if (setName.length() <= 25 )
    		{
    			courseName = setName; // set courseName
    		}
    
    		else {
    			courseName = setName.substr(0,25);
    
    			cout << "Name \"" << setName << "\" exceeds maximum length (25).\n"
    				<< "Limiting course name to first 25 characters.\n" << endl;
    		}
    	}
    
    string GradeBook::getCourseName()
    	{
    		return courseName;
    	}
    
    void GradeBook::setInstrName(string instName)
    	{
    		instrName = instName; // set instructor name
    	}
    
    string GradeBook::getInstrName()
    	{
    		return instrName;
    	}
    
    void GradeBook::displayMessage()
    	{
    		cout << "Welcome to the grade book for\n" << getCourseName() << endl;
    		cout << "This course is presented by: " << getInstrName() << endl;
    	}
    grade.h

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class GradeBook
    {
    	public:
    		GradeBook(string name, string instName); // constructor
    		void setCourseName(string setName); // set function for course Name
    		string getCourseName(); // get function for course Name
    		void setInstrName(string instName); // set function for instructor name
    		string getInstrName(); // get function for instructor name
    		void displayMessage(); // display course name function
    	private:
    		string courseName;
    		string instrName; // variable that stores course instructor name
    }; // class GradeBook end
    what am i doing wrong ?

    i get this error

    13: error: no match for 'operator<<' in 'std::cout <<
    (&grade1)->GradeBook::displayMessage()'

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    You don't need to the the std::cout in your main.
    Woop?

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    what do you mean ???

    ok when I try to run this then it works fine

    like
    Code:
    cout << grade1.getCourseName();
    but when I type displayMessage() instead of getCourseName()

    i cant compile then

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Because getCourseName returns a string and displayMessage returns nothing. How is std::cout supposed to output void? The displayMessage function already calls those functions with std::cout.
    Woop?

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    hey thanks,

    that was very easy but hell very difficult to spot

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    You are welcome.
    Woop?

  7. #7

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM