Error C2512 - No Appropriate default constructor available, i thought i put on in help :( ???

So i keep getting this error and ive included a constructor i think, any help to fix this issue would be greatly appreciated, im just trying to add an object to a vector and i know its not a good way but please focus on the issue I have and not how ugly my code is. thankyou.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <ctime>

#include "Dock.h"

using namespace std;

//time method using this way 
	time_t now = time(0);
	char* dt = ctime(&now);

	int entNum;
	string shipName;
	string shipSize;
	string shipRowPos;

	//creation of a new ship
	Ship newShip; <<<<<<<<<<<<<<<<<<<<<<< here is the error line :/

	//test just for debugging
	Row theRow;

	//Row vector.insert(Row vector.end(), Shipvector.begin(), Shipvector.end());

int main(int argc, char *argv[]) {

	fstream port;

	cout << "Welcome to Dock Manager v1.2" << endl;

	login();

	menu();

	cin >> entNum;

	switch (entNum)
	{
	case 1:	

	    port.open("portLog.txt", ios::in);

		cout << "Dock ship to port" << endl;
	
		cout << "Enter ship name" << endl;
		cin >> newShip.shipName;

		cout << "Enter ship size using S,M,L meaning Small, Medium or Large" << endl;
		cin >> newShip.shipSize;

		cout << "Ship Size: " << newShip.shipSize << ", and Ship Name: " << newShip.shipName << endl;

		theRow.dock(newShip);

		//open port log add ship with position and timestamp to portlog.txt
		//if no spaces for ships add to waiting list

		port << dt << " " << newShip.shipName << " " << newShip.shipSize << endl;; 

		break;
}
	port.close();

	cin.get();
	cin.ignore();

}


classes header file here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  /**
* @file Dock.h
*
*/

#ifndef DOCK_H
#define DOCK_H

#include <vector>
#include <string>

void login();

void menu();

class Ship {

public:

	std::string shipName;
	std::string shipSize;
	
	//default constructor
	Ship(std::string shipName, std::string shipSize);

};

class Row {

	std::vector<Ship> _lrgSpace;
	std::vector<Ship> _medSpace;
	std::vector<Ship> _smlSpace;
public:
	Row();

	bool dock(Ship newShip);
	
	bool dockL(Ship newShip);
	bool dockM(Ship newShip);
	bool dockS(Ship newShip);
 
private:
	
};

class Dock {

	std::vector<int> _Rows;

public:
	bool dock(Ship newShip);

	bool full() const;
};


#endif


here are my functions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  bool Row::dockL(Ship newShip)
{
	// always docking a ship in the large space

	// check whether there is space at all
	// check the size of the ship, and place it in the appropriate vector

	if (newShip.shipSize == "L" || newShip.shipSize == "l")

	{
		cout << "Dock ship: " << newShip.shipName << " in a large berth at. " << endl;

		if (_lrgSpace.size() < 2){
			_lrgSpace.push_back(newShip);
			return true;
		}
		else{
		return false;
		}; //add to waiting list

	}

	return true;
	// you can't - add to waiting list or get ride 
}

bool Row::dockM(Ship newShip){

	if (newShip.shipSize == "M" || newShip.shipSize == "m")
	{
		cout << "Dock ship: " << newShip.shipName << " in a berth at. " << endl;

		if (_medSpace.size() < 3){
			_medSpace.push_back(newShip);
			return true;
		}
		else if (_lrgSpace.size() < 2){
			_lrgSpace.push_back(newShip);
			return true;
		}
		else{
		return false;
		};
		//full

	}

	return true;
}

bool Row::dockS(Ship newShip){

	if (newShip.shipSize == "S" || newShip.shipSize == "s")
	{

		cout << "Dock ship: " << newShip.shipName << " in a berth at. " << endl;


		if(_smlSpace.size() < 5) {
			_smlSpace.push_back(newShip);
			return true;
		}
		else if (_medSpace.size() < 3) {
			_medSpace.push_back(newShip);
			return true;
		}
		else if (_lrgSpace.size() < 2) {
			_lrgSpace.push_back(newShip);
			return true;
		}
		else {
			return false;
		}
	}

	return true;
}


bool Row::dock(Ship newShip)
{
	
	if (newShip.shipSize == "S" || newShip.shipSize == "s")
	{
		return dockS(newShip);
	}
	else if (newShip.shipSize == "M" || newShip.shipSize == "m")
	{
		return dockM(newShip);
	}
	if (newShip.shipSize == "L" || newShip.shipSize == "l")
	{
		return dockL(newShip);
	}
	return true;
}
Line 22 tries to use the default constructor Ship(), which is not defined in the Ship class.

You can either make a default constructor or declare the newShip variable as a pointer. Ship *newShip;
Last edited on
thanks for the reply @smac89, however isnt the Ship(std::string shipName, std::string shipSize) a default contructor?
No a default constructor is one that takes no parameters. Your constructor takes parameters, so it cannot be said to be the default constructor.

Note that if you didn't specify a constructor, then the default constructor is used. Since you have defined a constructor that is not the default constructor, the only way an object of type Ship can exist is if you create it with any of the of those constructors you have defined.
Right I see when i make Ship(); the default constructor I get these errors :/ @smac89

1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall Ship::Ship(void)" (??0Ship@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'newShip''(void)" (??__EnewShip@@YAXXZ)


1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall Row::Row(void)" (??0Row@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'theRow''(void)" (??__EtheRow@@YAXXZ)
Can you show how you are defined the constructor?
Topic archived. No new replies allowed.