CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #3
    Join Date
    Aug 2009
    Posts
    440

    Re: Template operator overloading assistance

    Thanks for the reply. I've run into a problem that I want to debug with Code::Blocks (as opposed to either using gedit and gdb or Emacs and gdb). I am able to compile my code fine in Fedora 15, but not when using Code::Blocks (using GCC compiler). I am assuming my problem might be because I am separating a template class into a .h and .cpp file.

    Anyway the structure of my code is as follows:

    MyVector.h
    Code:
    #ifndef MYVECTOR_H
    #define MYVECTOR_H
    
    template <typename T>
    class MyVector
    {
    	public:
    		MyVector();
                    // Remaining Class Declarations
    };
    
    #include "MyVector.cpp"
    
    #endif // MYVECTOR_H
    MyVector.cpp
    Code:
    #include "MyVector.h"
    
    template <typename T>
    MyVector<T>::MyVector()
    {
    	capacity 		= 10;
    	vect_front	 	= 0;
    	vectsize		= 0;
    	vector 	 	        = new T[capacity];
    }
    
    // Remaining functions
    The error messages I am getting are:
    Code:
    error: redefinition of 'MyVector<T>::MyVector()'
    error: 'MyVector<T>::MyVector()' previously declared here
    Any idea why I am getting the above error messages with Code::Blocks? Any idea why I am able to compile this under Fedora without running into these errors? If you need to entire code, let me know. Thanks for any assistance.
    Last edited by Alterah; September 3rd, 2011 at 07:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured