issues with objects storing lists

so basically i have a row class which stores a list of characters as a doubly linked list
and i have a maze class which i want to store row objects as a doubly linked list

below is my code for the 2 classes

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
 
class row
{
private:
	list<char> chars;

public:
	row(){}

	row(row &other) {
		chars.clear();
		for(list<char>::iterator itr=other.getFirst(); itr != other.getLast(); itr++)
			chars.push_back(*itr);
		}

	void addChar(char temp){
		chars.push_back(temp);
	}

	list<char>::iterator getFirst() {
		return chars.begin();
	}

	list<char>::iterator getLast() {
		return chars.end();
	}

	int getSize()  {
		return chars.size();
	}

	void printRow() {
		for(list<char>::iterator itr= chars.begin();itr != chars.end();itr++)
			cout << *itr;
	}

};

		
class maze
{
private:
	list<row> rows;

public:
	maze() {}

	maze(maze &other) {
	   rows.clear();
	//   for(list<row>::iterator itr= other.getFirst(); itr != other.getLast(); itr++)
	//	   row.push_back(*itr);
	}

	void addRow(row rows1) {
        rows.push_back(rows1);
	}

	int getSize() {
		return rows.getSize();
	}

	

};



below is the error i get which i have no clue about

1>c:\program files\microsoft visual studio 9.0\vc\include\xmemory(52) : error C2558: class 'row' : no copy constructor available or copy constructor is declared 'explicit'

which takes me to somewhere in a STL template and thats where i lose it :(

any help would be greatly helpful

thanks
Last edited on
Couldn't you just do:

this->rows = other.rows;
You should probably use vectors or deques instead... you don't have at with lists, and trust me, you'll want it.

-Albatross
Last edited on
How about:

1
2
typedef list<char> Row;
typedef list<Row> Mase;
Anyway, on line 10, try:

 
row( const row & other ) {


EDIT: Also, you'll probably need to use const_iterator--that is, if you do not just use the assignment operator mentioned above.
Last edited on
i figured out what the problem is but dont know how to solve...

its when i declare a row object in the main...it doesnt know which constructor to call..thnx to g++ compiler it said candidates:row and row(&row)...the default or the copy....it should be clear that im calling the default constructor since im doing

row rows;

my program works fine if i kill the copy constructor but still im curious
Well, try explicitly stating the default constructor.

Also, you will need to do what morrecm suggested.

And also, you will need to do what I suggested.

-Albatross
and how do u explicitly call default constructor?

i tried
 
row rows=new rows(); 

but got an error...

also i HAVE to use linked lists since its in the specs

thanks everyone for the great help!
c++ is a monster and we need to join forces to bring it down :)
+1 moorecm

What OP is calling his copy constructor is not a copy constructor. Copy constructors
must take their argument by const reference.

Topic archived. No new replies allowed.