Thread: MSVC Template Constructor/Assignment Errors

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Question MSVC Template Constructor/Assignment Errors

    Okay, MSVC6 is making me nuts because it errors for reasons I am unable to determine. I doubt there is a problem with my code because it compiles cleanly with Borland and the it is quite straightforward...

    Here is exactly what I'm compiling with the errors listed on their corresponding lines. Any ideas?
    Code:
    Test.h
    #include <iostream>
    using namespace std;
    
    class Test {
    public:
      Test();
    
      Test(const Test &);
    
      template <typename T>
        Test(const T &);
    
    
      Test& operator=(const Test &);
    
      template <typename T>
        Test& operator=(const T &);
    };
    Code:
    Test.cpp
    #include <iostream>
    #include <string>
    #include "Trash.h"
    using namespace std;
    
    
    Test foo() {
      Test t;
      t = string("foo");
      return t;// 'Test::Test' : ambiguous call to overloaded function
               // no legal conversion of return value to return type 'class Test *'
    }
    
    Test foo2() {
      Test t;
      t = foo();// 'operator =' is ambiguous
      return t;// 'Test::Test' : ambiguous call to overloaded function
                // no legal conversion of return value to return type 'class Test *'
    
    }
    
    
    int main() {
      string str = "BLAH";
    
      Test t(str);
    
      Test t2;
      t2 = str;
      Test t3 = foo();// 'initializing' : cannot convert from 'class Test' to 'class Test'
                      //       No copy constructor available for class 'Test'
    
      return 0;
    }
    
    
    Test::Test() {
    }
    
    template <typename T>
    Test::Test(const T &) {
    }
    
    Test::Test(const Test &) {
    }
    
    template <typename T>
    Test& Test::operator=(const T &) {
      return *this;
    }
    
    Test& Test::operator=(const Test &) {
      return *this;
    }
    Last edited by LuckY; 07-22-2005 at 02:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function template has already been defined
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 04-14-2009, 10:17 AM
  2. template function v.s. template class
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2007, 01:46 AM
  3. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  4. Compiling using g++ and getting errors...
    By alvifarooq in forum C++ Programming
    Replies: 2
    Last Post: 09-24-2004, 08:36 AM
  5. MSVC 6 SP5 template errors
    By jdinger in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2003, 09:59 AM