C ++ templates and external function declarations
I have it:
template <typename T>
class myList
{
...
class myIterator
{
...
T& operator*();
}
}
...
template<typename T>
T& myList<T>::myIterator::operator*()
{
...
}
This gives me the following error: "expected initializer before" & "token". What should I do? I already tried adding "template myList :: myIterator" before this, but it didn't work.
0
master chief
source
to share
2 answers
Compiles Fine:
If you want to post code, it should be as simple as passable, but it should still be compileable. If you are cutting stuff, then you will probably remove the real bug you want to commit, and the people here are very good at understanding the problems if you show people the code.
In this situation, we can only put it in some code that you removed.
template <typename T>
class myList
{
public:
class myIterator
{
public:
T& operator*();
};
};
template<typename T>
T& myList<T>::myIterator::operator*()
{
static T x;
return x;
}
int main()
{
myList<int> a;
myList<int>::myIterator b;
int& c= *b;
}
0
source to share