Hi friends,

I'm learning to program in C++.
I'm using Notepad++ to author my code and Cygwin g++ to compile it.

main.cpp : in function 'int main() :
main.cpp : 38 : error: no match for 'operator << '

then a lot of jibberish and number of errors : 1

'

here take a look at the code

// Classes Practical
// Author : -

#include <iostream>
#include <string>

using namespace std;

class GradeBook{

public:
    //Constructor
    GradeBook( string parameter ){
        setObject( parameter );
    }
    
    //Member Functions
    string getObject(){
        return courseName;
    }
    
    void setObject( string parameter ){
        courseName = parameter;
    }
    
    void displayObject(){
        cout << "Data member now contains : " << courseName << endl;
    }

private:
    //Data Members
    string courseName;
};

int main(){
    
    GradeBook myObject( "You got Owned, g++ won't compile" );
    cout << "myObject initialized\n" << myObject.displayObject() <<  endl;
    
    return 0;
}

Thank you for your time and help.

displayObject() returns void -- that can't be used with cout.

cout always looks out for a type which it can output or another object of its own data type that is "ostream&" but you are passing a void type to it by using the myObject.displayObject() in line with cout.Rectify it and you are done.

@AncientDragon : Sorry your message was not uploaded when i started writing the post. :)

You cannot use a void returning function with cout.

Since you are outputting something on screen using displayObject(), why not just call it separately. Something like ...

GradeBook myObject( "You got Owned, g++ won't compile" );
cout << "myObject initialized\n";
myObject.displayObject();
cout<<endl;

@AD, Csurfer - Same here, when I started writing, your posts were not there :)

Solved! Thanks guys much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.