Question: I keep getting this error when I try to compile: Ship.cpp:10:1: error: prototype for Ship::Ship(std::string, int) does not match any in class Ship Ship::Ship(string sname,
I keep getting this error when I try to compile:
Ship.cpp:10:1: error: prototype for Ship::Ship(std::string, int) does not match any in class Ship Ship::Ship(string sname, int slength)
Compile command that I am using is:
g++ Ship.cpp BBoard.cpp test.cpp -o ship.out
Codes:
// Ship.hpp
3 #include
// Ship.cpp
1 #include "Ship.hpp" 2 3 4 using std::cout; 5 using std::cin; 6 using std::endl; 7 using std::string; 8 9 // Constructor 10 Ship::Ship(string sname, int slength) 11 { 12 13 name = sname; 14 length = slength; 15 damage = 0; 16 17 } 18 19 20 // Getters 21 string Ship::getName() { return name; } 22 int Ship::getLength() { return length; } 23 int Ship::getDamage() { return damage; } 24 25 // When a ship gets hit print the information 26 void Ship::takeHit() { 27 cout << name << "Is hit "; 28 this->damage++; 29 } 30 31 bool Ship::Destroyed(){ 32 return damage == length; 33 } ~
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
