-4

In this program I got the error

[Error] no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream}' and 'numcall')

I can't understand how to get rid of it!!

#include<iostream>

using namespace::std;


class numcall
{
int a,b;

public:
     numcall(int c,int d)
    {
        c = a;
        c = b;
        cout<<"Your First num is " << c << endl << "Your Second num is "<< d << endl;
        cout << "You are in PARAMETER CONSTRUCTOR";
    }   

    numcall(int u)
    {
        u = a;
        b = 0;
        cout << "Your First num is " << u << endl << "Your Second num is " << b << endl; 
        cout << "You are in PARAMETER CONSTRUCTOR";
    }

    numcall()
    {

    }
};

int main(void)
{
    numcall x = numcall();
    numcall y = numcall(3,4);
    numcall z = numcall(3);
    cout << x << endl << endl << y << endl << endl << z << endl;
}
Richard
  • 2,994
  • 1
  • 19
  • 31
RONIK SHAH
  • 3
  • 1
  • 2
  • 1
    You didn't define `operator<<` for `numcall`, exactly as the compiler tells you. – Kevin Dec 05 '17 at 16:50
  • Possible duplicate of [no match for operator << (operand types std::ostream) c++ OOP and Point](https://stackoverflow.com/questions/22714089/no-match-for-operator-operand-types-stdostream-c-oop-and-point) – Amadeus Dec 05 '17 at 16:51
  • unless you really really need to flush, please don't use endl https://stackoverflow.com/questions/213907/c-stdendl-vs-n it will really hurt your performance and put you into bad habbits – UKMonkey Dec 05 '17 at 16:51
  • Possible duplicate of [no match for ‘operator<<’ in ‘std::operator](https://stackoverflow.com/questions/22588163/no-match-for-operator-in-stdoperator) – Bill the Lizard Dec 05 '17 at 16:51

2 Answers2

1

You haven't defined the << operator for your class numcall, so the compiler doesn't know how to apply it.

So define it.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
0

You need to define a friend method for the << stream operator, otherwise he doesn't know what to print.

  friend ostream &operator<<(ostream &os, const numcall &numcall1) {
    os << "a: " << numcall1.a << " b: " << numcall1.b;
    return os;
}

This is just an example of implementation.

By the way there are other mistakes: c=a means assign a to c, you want to do the other way around. Welcome to the programming world mate ;)