I'm working on trying to figure out constructors and header files. Can ya'll help me out with this? I'm sure my code looks like a mess as I tried to piece together different solutions I've found. There's also an attempted copy constructor and operator function. Basically my problem is my source file says there is no default constructor for my class type. Any guidance would be greatly appreciated. Here's my header code:
You are creating your own constructor which means the blank default constructor can no longer be used so if you have anything like Car c in your source code it will not work. You could always add a blank constructor for that if you wanted by doing Car() {} in the class. Otherwise we would have to see your source code to see what exactly the problem is.
Just on another note you can not call any non-const functions from a const object, so either change const Car& c to Car& c or access the members directly.
Thanks! So I have my default and copy constructors working, no I just need to output the class members using a stream operator. I have incorporated it into the header file but it keeps telling me it can't convert const Car to Car & on line 38. Also, I have no idea how to call this stream operator in the main function.
You are getting that error because of what I mentioned.
Just on another note you can not call any non-const functions from a const object, so either change const Car& c to Car& c or access the members directly.
If you wanted to call it in your source code you would just do cout << car1 << endl;
> Just on another note you can not call any non-const functions from a const object,
> so either change const Car& c to Car& c or access the members directly.
... or make the methods const correct std::string Car::getMake() const{return Make;}