Unable to create instance of class

Hi,

I am having some difficulties when trying to create an object of a class. I have several classes. I have successfully created one using code like this:

 
		Ship*  ship = new Ship();


But when I go to do a similar thing for my class Rows. It says that incomplete type is not allowed and 'Rows' : no appropriate default constructor available

 
  Rows*  rows = new Rows();


This is the code for the Rows class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once

class Berths; 

#include "Berths.h"
#include "Ship.h"
#include <iostream>
#include <vector>

class Rows
{
public:
	Rows(void);
	~Rows(void);

	std::vector<Berths> _rows;
	int rows_Size;

	bool dock(Ship ship);

	bool undock(Ship ship);

};


Any ideas as to what I have done wrong?

Regards

Rows* rows = new Rows();

You're calling the default constructor here. Do you have your default constructor defined?

1
2
Rows(void); // change to Rows(void){}
~Rows(void);
The constructor which I have defined for the class is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include "Rows.h"


Rows::Rows(void)
{
	rows_Size = 10;
}


Rows::~Rows(void)
{
}


Hi,

I have created an instance of the class however I am unable to push_back the name of the ship to the vector.

1
2
3
4
5
6
7
 

if (rows->_rows.size != rows->rows_Size)
{
      rows->_rows.push_back (ship->name);
}

I get the following errors.

Error 4 error C2040: '!=' : 'unsigned int (__thiscall std::vector<_Ty>::* )(void) throw() const' differs in levels of indirection from 'int'

Error 3 error C2446: '!=' : no conversion from 'int' to 'unsigned int (__thiscall std::vector<_Ty>::* )(void) throw() const'

Error 5 error C2664: 'void std::vector<_Ty>::push_back(Berths &&)' : cannot convert parameter 1 from 'std::string' to 'Berths &&'

Error 1 error C3867: 'std::vector<_Ty>::size': function call missing argument list; use '&std::vector<_Ty>::size' to create a pointer to member


6 IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=Berths, _Alloc=std::allocator<Berths>]" matches the argument list
argument types are: (std::string)
object type is: std::vector<Berths, std::allocator<Berths>>







Topic archived. No new replies allowed.