Hello,
I'm having an error in my code plz someone solve my problem. I just want to multiply the element # 1 of an object array from the element # 2 of another object of same class and so on. Plz help me. Thx
Error: int MyCLass::getValue():
invalid conversion from 'int*' to 'int'
my code is:
//---------------------------------------------------------------------------
#include <iostream>//header file for input/output
using namespace std;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//class declaration and definition
class MyClass
{
//declare friend function of the class
friend MyClass operator*(const MyClass& x, const MyClass& y);
private:
int value[10];//data member of the class
public:
//declare and define default constructor
MyClass()
{
for(int i = 0; i < 10; i++)
{
value[i] = 0;//initialize array to 0 using for loop
}
}
//destructor of the class
~MyClass() {};
//define set function which initialize the array
void setValue(int v[])
{
value[9] = v[9];
for (int i = 1; i <= 10; i++)
{
v[i] = i;
}
}
int getValue() { return value; }//define get function
//define function which shows the results after multiplication of both arrays
MyClass show()
{
for(int i = 1; i <= 10; i++)
cout << value[i] << endl;
}
};//end of class definition
//---------------------------------------------------------------------------
//define the friend function of the class which multiplies two arrays
MyClass operator*(const MyClass& x, const MyClass& y)
{
MyClass tmp;
for(int i = 0; i < 10; i++)
tmp.value[i] = x.value[i] * y.value[i];
return tmp;
}
//---------------------------------------------------------------------------
//main function of the program
int main()
{
MyClass a, b, c;
cout << "Object 1 :" << endl;
b.show();
cout << "\nObject 2 :" << endl;
c.show();
a = b * c;//calling overloaded operator '*'
cout << "\nMultiplication of both objects:" << endl;
a.show();//show the results
cin.get();
return 0;//terminate the program successfully
}
//---------------------------------------------------------------------------