So basically the assignment was we had to create a doubly linked list that's templated generically instead of locked to a single data type. I've tried compiling both with gcc and msvc and both compilers are giving me roughly the same errors so I'm assuming its just my bad coding and not the quirkyness of one compiler or the other.
Currently, I'm getting errors saying that my classes in linkList.h
are not a template
../linkList.h:34: error: ‘llist’ is not a template type
../linkList.h:143: error: ‘iter’ is not a template type
../josephus.cpp:14: error: ‘llist’ is not a template
../josephus.cpp:14: error: aggregate ‘llist ppl’ has incomplete type and cannot be defined
../josephus.cpp:15: error: ‘iter’ is not a template
linkList.h
template<typename T>
class iter
{
public:
iter()
{
position = sentin;
container = sentin->payload;
}
T get() const
{
assert(position != sentin);
return position->payload;
}
void next()
{
position = position->next;
}
void previous()
{
position = position->prev;
}
bool equals(iter itr) const
{
return position == itr.position;
}
private:
node *position;
llist *container;
};
josephus.cpp
llist<int> ppl;
iter<int> pos;
int start = static_cast<int>(argv[1]) - 1;
int end = static_cast<int>(argv[2]) - 1;
Any help in this matter is much appreciated
Your forward declaration says llist
is a class:
class llist;
Then you say it is a template:
template<typename T>
class llist;
Similarly with iter
.
I don't know how you could make it compilable easily. However, you can make node
and iter
'inside' of llist
.
There are several issues.
class A;
is not the way you forward declare a templated class.
If A has a single templated parameter you need to say:
template<typename T>
class A;
If you say that after you've already said class A;
you're contradicting yourself. The next issue is simlar, friend class A;
if A is templated won't work, you need to say friend class A<T>;
or similar. Finally, static_cast<int>(argv[1])
will not compile (althought static_cast<int>(argv[1][0])
would, but is still not want you want). To convert a string to an integer meaningfully, you'll need to use atoi
, strtol
, stringstream
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With