this is my very first post and please understand if formatting is bad X)
So, in my class, I was required to use operator= function to make a class object equal to the second object of the same class.
class Car
{
private :
int a;
int b;
public :
void set(int x, int y)
{a = x;
b = y;
}
void output()
{cout << a << " " << b << endl;
}
Car & operator=(const Car & carB)
{set(int c, int d);
}
};
using namespace std;
int main()
{
Car car1(1, 2);
Car car2;
car2=car1;
car2.output();
return 0;
}
I understand that Car & operator=(const Car & carb) function allows me to make the car2 equal to car 1. However, I'm not quite understanding the type of the function here. Why is the function not void? And what does the reference signs(both) do in this code?
I am on my 2nd quarter of very first computer language. Please help! Thanks! :]