#include "CruiseShip.hpp"
#include "iostream"
usingnamespace std;
CruiseShip::CruiseShip( int num, string name, string year ) : Ship( name, year ) {
setPassengers( num );
}
void CruiseShip::setPassengers( int num ){
passengers = num;
}
int CruiseShip::getPassengers(){
return passengers;
}
ostream& operator<< ( ostream& os, const CruiseShip& info ){
return os << "Name: " << info.getName() << endl << "Passengers: " << info.passengers << endl;
} //the error is right at the return line saying "Member function 'getName' not viable: 'this'
//argument has type 'const CruiseShip', but function is not marked const"
#include "CruiseShip.hpp"
#include "Ship.hpp"
#include <iostream>
#include <vector>
usingnamespace std;
int main() {
vector< Ship* > ptr; //I am using vector because I will add more derived
//classes later to add in here
Ship* cruise = new CruiseShip( 50, "David", "2018" );
ptr.push_back(cruise);
cout << *ptr.at[0]; // error here stating "Reference to non-static member function
//must be called
}
I want to try to use a simple 'cout' to display the data member "Passenger" from CruiseShip class and the data member "Name" from the base class!
Hope I address my problem clearly and if not, I will add more as I get replies.
Also add const at in the same position on the function definitions.
The other error is that you are trying to use the at member function of the vector class, but instead of using parentheses for the argument you've used brackets.