[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3449.0. "Strange Behavior" by RHETT::HALETKY () Thu Feb 13 1997 15:40

    Hello
    
    We have a strange thing:
    
    If we compile the follwoing code we get unresolved externals:
    //test.cxx...
    //
    // Memory allocation comparison between STL and MALLOC
    //On our alpha station -
    //  if you include the class declaration in the same file -- you get
    unresolved
    //  For example: deque<CShazbot>::~deque<CShazbot>(void)
    //
    //  However, if you declare the calss and typedefs in an include file,
    it builds
    //
    //      Then the plot sickens. If you go back to inlining the class
    declaration.
    // it builds just fine.
    //  Oh how can it be?
    //  If you delete the files in the cxx_repository... it breaks again.
    //
    //  One side effect of this problem is that I cannot make use of
    typedef'd STL v
    // and deques in class LIBRARIES without getting LOADS of unresolved
    externals..
    //
    //  All I care about is a workaround....
    
    #include <stdio.h>
    
    #if 1
    #include <vector>
    #include <deque>
    class CShazbot {
            public:
                    CShazbot(void);
                    ~CShazbot(void);
            public:
                    int m_word;
            };
    typedef deque<int> T_INT_Q;
    typedef vector<CShazbot> T_SHAZ_V;
    typedef deque<CShazbot> T_SHAZ_Q;
    
    #else
    #include "shazbot.h"
    #endif
    CShazbot::CShazbot (void) {}
    CShazbot::~CShazbot (void) {}
    
    int main (int argc,char** argv)
    {
            T_INT_Q myQ;
            T_SHAZ_Q shazQ;
            printf ("Success with STL\n");
            return 0;
    }
    
    
    cxx c.cxx 
    cxx: Error:
    ./cxx_repository/deque__T8CShazbot21allocator__T8CShazbot.cxx, line 4:
    In this declaration, the argument "CShazbot" for template parameter T
    is an expression where a type is expected, or vice versa.
    typedef deque<CShazbot, allocator<CShazbot > > __dummy_;
    --------------^
    cxx: Error:
    ./cxx_repository/deque__T8CShazbot21allocator__T8CShazbot.cxx, line 4:
    In this declaration, the argument "CShazbot" for template parameter T
    is an expression where a type is expected, or vice versa.
    typedef deque<CShazbot, allocator<CShazbot > > __dummy_;
    ----------------------------------^
    ld:
    Unresolved:
    deque<CShazbot, allocator<CShazbot> >::~deque<CShazbot,
    allocator<CShazbot> >(void)
    
    
    Yet if I recompile with the 'if 1' set to 'if 0' in the code and
    include the following header it works:
    //shazbot.h
    //Include file for class declaration... and STL collections
    #include <vector>
    #include <deque>
    
    #ifndef __SHAZBOT_H__
    class CShazbot {
            public:
                    CShazbot(void);
                    ~CShazbot(void);
            public:
                    int m_word;
            };
    typedef deque<int> T_INT_Q;
    typedef vector<CShazbot> T_SHAZ_V;
    typedef deque<CShazbot> T_SHAZ_Q;
    #endif
    
    Then if I go and set the #if 0 back to #if 1 and recompile it will also
    work as the proper cxx_repository entries exist.
    
    What's up?
    
    Best regards,
    Ed Haletky
    
T.RTitleUserPersonal
Name
DateLines
3449.1I think you're hitting the known automatic instantiation restrictionDECC::J_WARDThu Feb 13 1997 16:165
You only need to move the declaration of
CShazbot (or any template argument) to
its own header file. I think this was
already mentioned in note 3318 and note 3245.