tags:

views:

416

answers:

2

I have this:

template <typename T>
class myList
{
    ...
    class myIterator
    {
        ...
        T& operator*();
    }
}
...
template<typename T>
T& myList<T>::myIterator::operator*()
{
    ...
}

That is giving me the following error: "expected initializer before '&' token". What exactly am I supposed to do? I already tried adding "template myList::myIterator" before it, but that didn't work.

+3  A: 

How about some semicolons and publics:

template <typename T>
class myList
{
public:
    class myIterator
    {
    public:
        T& operator*();
    };
};
David Norman
Marcin
yeah builds for me too. I dunno what is messed up with OP's code -.- he should really show the code in ... .
Johannes Schaub - litb
Be careful with templates if you don't instantiate them not all semantic checking is done (because without T its not possible).
Martin York
A: 

Compiles Fine:
If you want to post code it should be as simple as passable, BUT it should still be compilable. If you cut stuff out will nilly then you will probably remove the real error that you want fixed and the people here are real good at finding problems if you show people the code.

In this situation we can only put it down to some code that you have 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;
}
Martin York