0
#include <iostream>

using namespace std;

class PrintName{
public:
    void studentName(){
        cout<<"Name       : "<<studentName<<endl;
    }
};

class MathClass{
public:
    void multiplicationFunc(int x, int y){
        cout<<"Result     : "<<(x*y)<<endl;
    }
};

int main()
{
    cout<<endl;
    PrintName PN;
    PN.studentName("Mark", "Santo");

    MathClass MC;
    MC.multiplicationFunc(10,5);
}

I am new to C++ and am learning about classes and objects. From what I gathered classes are ways to group functions and objects is the ability to access them? I am having trouble getting this code to work, I receive an error on line 15 for 'error: no match for 'operator<<'. I am trying to fix my class in order for the main function to work. The output should simply be 'Name : Mark Santo' 'Result : 50'

Thank you for your help everyone!

Yuki mB
  • 23
  • 4

1 Answers1

1

It seems like there is no error on line 15. Instead, you did not define the variable studentName in your void studentName() function in line 8. Also, you used 2 arguments for studentName() in line 23, where the original function is not taking any. This is the corrected code:

#include <iostream>

using namespace std;

class PrintName{
public:
    void studentName(string x, string y){
        cout<<"Name: " << x << " " << y << endl;
    }
};

class MathClass{
public:
    void multiplicationFunc(int x, int y){
        cout<<"Result: " << x*y << endl;
    }
};

int main()
{
    cout << endl;
    PrintName PN;
    PN.studentName("Mark", "Santo");

    MathClass MC;
    MC.multiplicationFunc(10,5);
}