Im пытается поместить информацию из другого класса в класс списка, основанный на узле. Например, у меня есть карточка класса, а затем я хочу поместить те карты, которые находятся в массиве, в мой класс списка, основанный на узлах. IM просто пытается разглядеть синтаксис. Нужно ли сделать мой класс карты другом узла и класса списка.Использование классов структуры данных (список узлов) с другим классом
У меня есть в общей сложности 2 класса (узел и список), которые будут содержать информацию из класса карты. Я знаю, что мне нужно создать шаблон узла и список, im запутался, как и почему?
./class.h:5:7: error: redefinition of 'card'
class card {
^
./class.h:5:7: note: previous definition is here
class card {
^
In file included from project8.cpp:9:
In file included from ./nodallist.cpp:2:
In file included from ./listN.h:4:
In file included from ./class.cpp:3:
./class.h:35:7: error: redefinition of 'player'
class player{
^
./class.h:35:7: note: previous definition is here
class player{
^
In file included from project8.cpp:9:
./nodallist.cpp:7:7: error: out-of-line definition of 'Node' does not match any
declaration in 'Node'
Node::Node(card value, Node* nodeyo)
^~~~
./nodallist.cpp:9:5: error: assigning to 'char' from incompatible type 'card'
data=value;
^~~~~~
./nodallist.cpp:149:12: error: out-of-line definition of 'insertAfter' does not
match any declaration in 'List'
bool List::insertAfter(card value)
^~~~~~~~~~~
./nodallist.cpp:153:18: error: no matching constructor for initialization of
'Node'
Node *newd= new Node(value,NULL);
^ ~~~~~~~~~~
./listN.h:12:3: note: candidate constructor not viable: no known conversion from
'card' to 'char' for 1st argument
Node(char, Node*);
^
./listN.h:10:7: note: candidate constructor (the implicit copy constructor) not
viable: requires 1 argument, but 2 were provided
class Node{
^
In file included from project8.cpp:9:
./nodallist.cpp:160:19: error: no matching constructor for initialization of
'Node'
Node *noden= new Node(value,cursor->next);
^ ~~~~~~~~~~~~~~~~~~
./listN.h:12:3: note: candidate constructor not viable: no known conversion from
'card' to 'char' for 1st argument
Node(char, Node*);
^
./listN.h:10:7: note: candidate constructor (the implicit copy constructor) not
viable: requires 1 argument, but 2 were provided
class Node{
^
In file included from project8.cpp:9:
./nodallist.cpp:167:12: error: out-of-line definition of 'insertBefore' does not
match any declaration in 'List'
bool List::insertBefore(card value)
^~~~~~~~~~~~
./nodallist.cpp:171:19: error: no matching constructor for initialization of
'Node'
Node *newd= new Node(value,NULL);
^ ~~~~~~~~~~
./listN.h:12:3: note: candidate constructor not viable: no known conversion from
'card' to 'char' for 1st argument
Node(char, Node*);
^
./listN.h:10:7: note: candidate constructor (the implicit copy constructor) not
viable: requires 1 argument, but 2 were provided
class Node{
^
In file included from project8.cpp:9:
./nodallist.cpp:180:14: error: assigning to 'char' from incompatible type 'card'
cursor->data=value;
^~~~~~
./nodallist.cpp:185:12: error: out-of-line definition of 'remove' does not match
any declaration in 'List'
bool List::remove(card &value)
^~~~~~
./nodallist.cpp:225:12: error: out-of-line definition of 'replace' does not
match any declaration in 'List'
bool List::replace(card value)
^~~~~~~
./nodallist.cpp:233:13: error: assigning to 'char' from incompatible type 'card'
cursor->data=value;
^~~~~~
./nodallist.cpp:238:12: error: out-of-line definition of 'getCursor' does not
match any declaration in 'List'
bool List::getCursor(card &value) const
^~~~~~~~~
project8.cpp:19:12: error: redefinition of 'SPACE'
const char SPACE = ' ';
^
./class.cpp:9:12: note: previous definition is here
const char SPACE= ' ';
Вам нужны шаблоны. – David