linking prob - undefined func, but I believe it's defined.

This is a discussion on linking prob - undefined func, but I believe it's defined. within the C++ Programming forums, part of the General Programming Boards category; Here's the code snip: Code: template<typename T> class matrix3 { ... friend vector3<T> operator * (const matrix3<T>& a, const vector3<T>& ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    72

    linking prob - undefined func, but I believe it's defined.

    Here's the code snip:
    Code:
    template<typename T>
    class matrix3
    { ...
      friend vector3<T> operator * (const matrix3<T>& a, const vector3<T>& v);
      ...
    };
    
    template<typename T>
    vector3<T> operator * (const matrix3<T>& a, const vector3<T>& b) 
    {
      // do stuff, 
      return vector3<T>(foo,bar,gah);
    }
    
    ------
    
    void otherFunc() // in another file
    {
      vector3f foo = someMatrix * someVector;
    }
    But the linker seems to think that the "*" function is not defined for vec = mat * vec:

    error LNK2019: unresolved external symbol "class vector3<float> __cdecl operator*(class matrix3<float> const &,class vector3<float> const &)" (??D@YA?AV?$vector3@M@@ABV?$matrix3@M@@ABV0@@Z) referenced in function "void __cdecl otherFunc()"

    ideas? Problem with template (again)?

    I'm using MSVC .NET on a Win XP machine.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904

    Re: linking prob - undefined func, but I believe it's defined.

    how is your code set up?

    this would be the optimal way to set it up:
    matrix3.h
    Code:
    template<typename T>
    class matrix3
    { ...
      friend vector3<T> operator * (const matrix3<T>& a, const vector3<T>& v);
      ...
    };
    matrix3.cpp
    Code:
    #include "matrix3.h"
    template<typename T>
    vector3<T> operator * (const matrix3<T>& a, const vector3<T>& b) 
    {
      // do stuff, 
      return vector3<T>(foo,bar,gah);
    }
    otherfile.cpp
    Code:
    #include "matrix3.h"
    
    void otherFunc() // in another file
    {
      vector3f foo = someMatrix * someVector;
    }
    if it isn't like that, then do it like that, and it should work

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    72
    it is like that. - matrix.h/cpp, and other.cpp with the call.

    other ideas?

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    what is vector3f? i noticed that in your code, but the linker error says it's looking for vector3<float> are they the same thing?

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    72
    Originally posted by jverkoey
    what is vector3f? i noticed that in your code, but the linker error says it's looking for vector3<float> are they the same thing?
    they are... sorry, I should I have been more clear on that...
    Code:
    typedef vector3<float> vector3f;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined Reference when linking a library
    By steve1_rm in forum C Programming
    Replies: 7
    Last Post: 03-12-2008, 06:34 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM
  4. Undefined Variables that ARE defined
    By Teema in forum C Programming
    Replies: 3
    Last Post: 12-03-2002, 01:14 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21