LinkedList
Jul 19, 2013 at 8:11am UTC
Hi, I am trying to implement a simple Linked List. When I declare the class DbLinked, the compiler give me an error:2
\progetto1\main.cpp required from here
Error] 'DbLinked<T>::next' has incomplete type
[Error] declaration of 'class DbLinked<int>
The declaration of the Class is the following:
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
template <class T>
class DbLinked
{
//dato: รจ la variabile che contiene l'informazione di un certo record
T dato;
DbLinked next;
public :
DbLinked()
{
}
DbLinked(T& elem)
{
dato=elem;
}
~DbLinked()
{
}
void add(T& elem )
{
}
bool remove(T& elem)
{
}
};
while the fuction main() is written:
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream>
#include "classi.h"
#include<conio.h>
using namespace std;
int main()
{
int a=5;
int b=4;
DbLinked<int >lista(a);
getch();
return 0;
}
why the compiler give me this error?
Jul 19, 2013 at 8:24am UTC
next
is an instance of DbLinked
, but DbLinked
the encompassing class. That's not possible.
you want to do this DbLinked *next; // As a pointer
Don't forget to set the pointer to null in you constructor
Jul 19, 2013 at 8:58am UTC
It would be better if you would define inside DbLinked some internal class named for example as Node.
Topic archived. No new replies allowed.