Me, Myself and I
I am da` stack!

Programming Tip #0

Posted on 05 Jun 2008 under c, programming, tip .

I'll start a series of programming tips and tricks in various languages, and this will be the first one :)

These are very rare, strange and uncommon stuff for the normal mortals ... oK enough chit-chat let's see some code.

What's wrong with the following code snippet?

template <typename T>
class obj
{
    public:
        obj(){};
        virtual ~obj()
        {
            map<unsigned long, T*>;::iterator it;
            //...
            //...
        };
    
    //...
    //...
    //...
        
    private:
        map<unsigned long,T*> items;
};

Well this will fail, at this line map<unsigned long, T*>::iterator it; giving a rather confusing and cryptic error message which looks something like this error: expected `;' before it . Hmmm ...

This can be solved by putting the typename keyword at the beginning of that line. It took me some time to figure out what was the problem :)

Happy coding, and may the source be with you!

Comments | Read More

blog comments powered by Disqus