Thread: silly little error

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    3

    silly little error

    Hello!!!!

    I have a simple class - one constructor should take a parm of type std::vector<T>::iterator... but i get compilation errors.... any idea why?

    im really stuck here, please help poor, poor little me
    Cheers for any help!!




    listed is the whole program...

    Code:
    #include <vector>
    
    
    //
    // Class MOO - doesn't do anyting
    //
    template <class T>
    class MOO
    {
    public:
    	MOO()
    	{
    	}
    
    
            // Im getting a compilation error on this line
    	MOO(std::vector<T>::iterator m)
    	{	
    	}
    
    	~MOO()
    	{
    	}
    };
    
    //
    // Main function
    //
    int main()
    {
    	MOO<int> moo;
    }


    the compile error(s) are
    error C2059: syntax error : ')'
    error C2143: syntax error : missing ';' before '~'
    error C2146: syntax error : missing ')' before identifier 'm'
    error C2146: syntax error : missing ';' before identifier 'm'
    error C2501: 'MOO<T>::m' : missing storage-class or type specifiers
    error C2838: 'iterator' : illegal qualified name in member declaration
    error C3254: 'MOO<T>' : class contains explicit override 'iterator' but does not derive from an interface that contains the function declaration
    fatal error C1903: unable to recover from previous error(s); stopping compilation

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    I *think* this is where you need the typename keyword, like so:
    Code:
    MOO(typename std::vector<T>::iterator m)
    Basically, because of templating, the compiler doesn't realize that std::vector<T> is a typename as opposed to a type.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    3
    your spot on Stuka; i owe u a beer

    Im confused at why the function:
    MOO(std::vector<T>::iterator m) requires typename.

    But, this doesnt require typename:
    MOO(std::vector<T> m) doesnt require a typename.

    in fact, im a little confused with the "typename" keyword. Im a little new to templates (in case you couldn't tell already hehe)
    Last edited by meatcow; 01-23-2006 at 11:45 PM.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    52
    I'm not an expert - just read a CUJ article on typename not to long ago. The reason, I think, is because of the additional scoping operator in there, and the way the compiler looks up names. It just has to have a nudge in that case, because it's looking for a concrete type of std::vector<T> which has a member named iterator. The typename keyword tells it that the whole mess (std::vector<T>::iterator) is a typename.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    3
    k makes sense... ill gooogle that document. Thanks so much.... thats 2 beers now.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM