Thread: tricky stuff...

  1. #1
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66

    tricky stuff...

    Ok, so this is the continuing saga of porting my code from VC6.0 to VC7.1...

    so here's the story... i have some libraries that i have rebuilt with no problems under VC7.1... now i have another project that uses this library and when i come to build it, i get 2 linker errors:

    >>>

    ashlibd.lib(ImagedTarget.obj) : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl ashlib:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class ashlib::Tuple2<float>)" (??6ashlib@@YAAAV?$basic_ostream@DU?$char_traits@D @std@@@std@@AAV12@V?$Tuple2@M@0@@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl ashlib:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class ashlib::ImagedTarget const &)" (??6ashlib@@YAAAV?$basic_ostream@DU?$char_traits@D @std@@@std@@AAV12@ABVImagedTarget@0@@Z)
    ashlibd.lib(Target.obj) : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl ashlib:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class ashlib::Tuple3<float>)" (??6ashlib@@YAAAV?$basic_ostream@DU?$char_traits@D @std@@@std@@AAV12@V?$Tuple3@M@0@@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl ashlib:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class ashlib::Target const &)" (??6ashlib@@YAAAV?$basic_ostream@DU?$char_traits@D @std@@@std@@AAV12@ABVTarget@0@@Z)

    >>>

    now, i have tried everything i can think of, and i really can't figure it out, but the linker errors are refering to the overloaded operator '<<' in my Tuple2 and Tuple3 classes:

    Code:
    #ifndef TUPLE2_H
    #define TUPLE2_H
    
    #include <cmath>
    #include <fstream>
    #include <iostream>
    
    namespace ashlib {
    
    template<class T> class Tuple2 {
    public:
        T x;
        T y;
    
    public:
        Tuple2() { x=y=0; }
    ...
    
        friend std::ostream& operator<<(std::ostream& os, Tuple2<T> v);     
    };
    
    ...
    
    template<class T> std::ostream& operator<<(std::ostream& os, Tuple2<T> v) {
        return os << "[" << v.x << "," << v.y << "]";
    }
    
    }//end namespace
    
    #endif
    so, there is this issue of the method not being a member function, due to the 'friend'... so maybe thats the issue... but i can't figure out how else to do it.... the annoying thing is that this all works fine under VC6.0 ...... ARRGGGGHHH!!!!!! please help.
    "take the long road.... and walk it."

  2. #2
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    i think it is something to do with this:

    http://msdn.microsoft.com/library/de...rorlnk2019.asp

    but i can't figure out what to do to correct it.
    "take the long road.... and walk it."

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    To resolve, according to this article, you would do:
    friend std::ostream& operator<< <T>(std::ostream& os, Tuple2<T> v);
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    yeah, i tried that, but then the library won't compile:

    >>>

    c:\dev\dev\res\ASHLIB\src\ashlib\geometry\Tuple3.h (67) : error C2143: syntax error : missing ';' before '<'
    c:\dev\dev\res\ASHLIB\src\ashlib\geometry\Tuple3.h (68) : see reference to class template instantiation 'ashlib::Tuple3<T>' being compiled
    c:\dev\dev\res\ASHLIB\src\ashlib\geometry\Tuple3.h (67) : error C2433: 'ashlib:perator`<<'' : 'friend' not permitted on data declarations
    c:\dev\dev\res\ASHLIB\src\ashlib\geometry\Tuple3.h (67) : error C2530: 'ashlib:perator`<<'' : references must be initialized
    c:\dev\dev\res\ASHLIB\src\ashlib\geometry\Tuple3.h (67) : error C2238: unexpected token(s) preceding ';'
    c:\dev\dev\res\ASHLIB\src\ashlib\geometry\Tuple3.h (80) : error C2904: '<<' : name already used for a template in the current scope

    >>>

    perhaps because its an overloaded operator? i don't know.... has anyone else run into this before?
    "take the long road.... and walk it."

  5. #5
    Registered User dug's Avatar
    Join Date
    Jun 2003
    Posts
    66
    i have found the solution:

    Code:
    namespace ashlib {
    
    
    	template <class T>	class Tuple2;
    	template <class T>	std::ostream& operator << (std::ostream&, Tuple2<T>);
    
    template<class T> class Tuple2 {
    
    public:
    	T x;
    	T y;
    
    public:
    	Tuple2() { x=y=0; }
    	...
     
            friend std::ostream& operator<< <>(std::ostream& os, Tuple2<T> v); 	
    };
    
    ...
    
    template<class T> std::ostream& operator<<(std::ostream& os, Tuple2<T> v) {
    	return os << "[" << v.x << "," << v.y << "]";
    }
    
    }//end namespace
    
    #endif
    "take the long road.... and walk it."

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Nice one. Have to remember that, I'm sure I'll eventually run across that problem too.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tab key stuff. C+WinAPI is killing me. Please help.
    By Templario in forum Windows Programming
    Replies: 5
    Last Post: 11-21-2002, 03:35 PM
  2. arguments, directories and stuff...
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-26-2002, 05:46 PM
  3. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM
  4. Linked lists and file i/o, and some other stuff
    By ninja in forum C++ Programming
    Replies: 9
    Last Post: 05-19-2002, 07:15 PM
  5. Stocks 'n' stuff...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-20-2001, 05:36 PM