???? ???????? ????????? (STL) ?? ?? ???? ?? ???? ????? STL ???????? ?? ?????? ?? ???? ?? ??? instantiation ??????? ???? ????

???? ?????? ???? ??????
???? ID: 168958 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ???? ????? ???? ?? ?? ????? ????? ???? ?? ??? ???? ????:
  • ???? ???? ???????? ????????? ?? ???? instantiation ??????? (STL) ?????
  • ?? ????, ?????? ?? STL ?? ?? ???? ????? ??????? ?????????
????? ??? ?? ?? ???? generalized ???????? ??????? ?? ???? ?? ???? ??? ???????? ?? ???? ???? ????; ??????, ??? ???????? ???????? ???? ??? ?? ???? ????? ?? ???? ??? ????????? ?????? instantiation ?? point ?? ???? ?????? ??????? "????? <int>;" ?? ??? STL ????? ???? instantiates. Forces ???? ????? ?? ??? ??????? ?? instantiation <int>??????? ?? ???? ?? ???.</int></int>

?? ????? ??? ?? ??? STL ?????? (???, ???, ??????, ????, deque) ??????? ???? ???? ?? ????? ????? ??? ??????? ???????? ?? ??? ?? ???? ???? ?? ??? ???? ??????? ??? ?? ??????

???? ???????

????? C++ 5.0 ?? ??????? ????, ?? ???? ?? ??? ???????? ???? ?? ??? instantiation ???????? ?? instantiation ??????? ???? ?? ???? ??? ???????? ???? instantiation ?? ??????? ???? ?? ??? ????? ???????? ?? ????? ????:

??? STL ???? ?? ??????? ???? ?? ???

  1. ?? ????? ??? DLL. exe ?????, ???? ???? DLL ?? ??? C ??? ????? ?? ???????? ?? ?? ????? Msvcrt.lib (????? ??????) ?? ??? ???? ?? ????? Msvcrtd.lib (????? ????) ?? ??? ???? ?????
  2. DLL DLL ?? STL ???? instantiation ?? ??????? ???? ?? ??? ???????? instantiation declaration ??? __declspec ?????????? ?????? ??????
  3. . Exe ????? ??? extern ?? __declspec specifiers ???????? instantiation declaration ??? ?? DLL ???? ?? ???? ???? ?? ??? ?????? ?????? ?? ???? ??????? C4231 ??? ?????? "nonstandard ????????? ?? ?????: ???????? ?????? instantiation ???? ?? ???? ' extern'." ?? ?? ??????? ?? ????? ???? ?? ???? ????

?? ???? ?? ??? STL ???????? ?? ?? ???? ????? ?????? ??????? ???? ?? ???

  1. ?? ????? ??? DLL. exe ?????, ???? ???? DLL ?? ??? C ??? ????? ?? ???????? ?? ?? ????? Msvcrt.lib (????? ??????) ?? ??? ???? ?? ????? Msvcrtd.lib (????? ????) ?? ??? ???? ?????
  2. DLL DLL ?? STL ???? instantiation ?? ??????? ???? ?? ??? ???????? instantiation declaration ??? __declspec ?????????? ?????? ??????

    ???::?? ??? 2 ?? ??? ???? ????? ?? instantiation ???? ????? ????? ?? ??? ????? STL ???? ?? ??????? ???? ??????
  3. DLL ???? ?? DLL ??? ??????? ???? ?? ??? ???? ?? declaration ??? __declspec ?????????? ?????? ??????
  4. . Exe ????? ?? DLL ???? ?? ???? ???? ?? ??? ???? ?? declaration ??? __declspec ?????????? ?????? ??????

    ??? ??????? ???? ?? ?? ??? ??? ?? ?? ?? ???? ???? ???? ??, ?? ?? ???? ???? ?? ??????? ???? ?????? ??? ???? ?? ?? ??????? ?? ??? ???, ?? ???? ?? ?????? ?? ???? ??????? ???, ?? ???? ?????? ??????? ???? ?? ?? ???? ??????? ???
???::??? STL ???? ???? STL ???? ?? ????? ????? ?? ???? ?? ??????? ?? ???? ????? ??????? ???? ????? ?? ???? ??????? ?????????? ??? ???????? ???? ??? ??? ???? ?? ??????? ???? 1; ?? ?? ?? ??, /W2, /W3, ?? /W4 ?? ??? ??????? ????? ??????? ???? 4 STL ????? ??? ?? ??? ??????? ????? ?? ?? ???? ????? ?? ?? ??????? ??? ?? ???? ?? ??? ???????? ???? ???

??? STL ???? ?? ??????? ???? ??? ??? ?? ???? ?? ??????? ???? ???? ?? ????? ?????? ?? ???, deque ??? ??? ??????? ???? deque::iterator ??? ??? ?? deque ??????? ???, ?? ???? ?? ??????? ?? ?? ?? deque::iterator ??????? ???? ????? ??????? ??????? ??? ?? deque::iterator ???????, ?? ??????? ?? ?? ?? deque ??????? ?????? ????? ???? ?? ???? ?????? ?? ???????? ?? ?? ???? ???? ??, ?? ??? ?? ?? ???? ??? ???? ???? ?? ???? re-instantiated ?? ??????? ?? ??? ??? ??????? ??? ??????? ???? ?? ???? ?? ???? STL ???????? ??? vector ??? ???? ?????? (??????, ???, ???, ??????, ????, deque) ??? ??????? ???? ??? ?? ?? ??????? ???? ???? ?? ???? ???

?? ?? ???? ????-??????? ?????? (UDT) ?? ??? parameterized STL ???????? ???????, ?? ???????? ????????? ???? ???? < and="=" for="" your="" udt.="" for="" example,="" if="" you="" export=""> <myclass>, MyClass::operator ????????? ???? ???? < and="" myclass="" operator="=." this="" is="" because="" all="" stl="" container="" classes="" have="" member="" comparison="" operators="" that="" require="" the="" existence="" of="" the="" operators=""> < and="=" for="" the="" contained="" type.="" normally,="" these="" are="" not="" instantiated="" because="" they="" are="" not="" used.="" when="" you="" instantiate="" an="" instance="" of="" a="" template="" class,="" all="" member="" functions="" are="" generated.="" because="" the="" stl="" container="" classes="" have="" member="" functions="" that="" use="" the="" operators="">< and="=" for="" the="" contained="" type,="" you="" must="" implement="" them.="" if="" comparing="" objects="" of="" your="" udt="" does="" not="" make="" sense,="" you="" can="" define="" the="" comparison="" operators="" to="" simply="" return="" "true."=""></></myclass>

?????? _DLL compiling ?? (?? ?????? implicitly ????????? ?? ?? C ?????? DLL ??????? ?? ???? ???? ?? ??? /MD ?? /MDd compiling), ????? STL ???? ???, ??????? ??????? ???????? ?? ?????? ?? ???? ?? ????? ?? ????? ???????? ?? ???? ??, ?? ?? ???? ?? ?? C ?????? DLL ?????? ??????? ???? ???? ?????, ?? ??????? ???? ?? ???? ?????? ???? DLL ??? ?? ???? ???? ???? ???? ?? ?? ?? ?? C ??? ????? ?? DLL ?? ??????? ????? ???????? ????? ????????? ?? ??? ???? ?????? ?? ???? ???? ???? ?????:
Header      STL template class
------------------------------
<IOSFWD>    basic_ios
<IOSFWD>    <IOSFWD>
<IOSFWD>    basic_istream
<IOSFWD>    basic_string (also typedef'd as string and wstring)
<IOSFWD>    complex
<LOCALE>    messages
<XLOCALE>   codecvt
<XLOCALE>   ctype
<XLOCMON>   moneypunct
<XLOCMON>   money_get
<XLOCMON>   money_put
<XLOCNUM>   numpunct
<XLOCTIME>  time_get
<XLOCTIME>  time_put
<XSTRING>   basic_string (also typedef'd as string and wstring)
				
???-?? ???????? ???????? ?? ????? ???? ???? ?? ?? ???-?? ??????? ?????? ?? ???????? declared ??? ?? ??????? ????? ?? ??? ????? ????????? ????? ??? ???? ??????

????? ???

   // -------------------------------------------
   // MYHEADER.H
   //disable warnings on 255 char debug symbols
    #pragma warning (disable : 4786)
   //disable warnings on extern before template instantiation
    #pragma warning (disable : 4231)

    #include <vector>

    // Provide the storage class specifier (extern for an .exe file, null
    // for DLL) and the __declspec specifier (dllimport for .an .exe file,
    // dllexport for DLL).
    // You must define EXP_STL when compiling the DLL.
    // You can now use this header file in both the .exe file and DLL - a
    // much safer means of using common declarations than two different
    // header files.
    #ifdef EXP_STL
    #    define DECLSPECIFIER __declspec(dllexport)
    #    define EXPIMP_TEMPLATE
    #else
    #    define DECLSPECIFIER __declspec(dllimport)
    #    define EXPIMP_TEMPLATE extern
    #endif

    // Instantiate classes vector<int> and vector<char>
    // This does not create an object. It only forces the generation of all
    // of the members of classes vector<int> and vector<char>. It exports
    // them from the DLL and imports them into the .exe file.
    EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<int>;
    EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<char>;

    // Declare/Define a class that contains both a static and non-static
    // data member of an STL object.
    // Note that the two template instantiations above are required for
    // the data members to be accessible. If the instantiations above are
    // omitted, you may experience an access violation.
    // Note that since you are exporting a vector of MyClass, you must
    // provide implementations for the operator < and the operator ==.
    class DECLSPECIFIER MyClass
    {
    public:
        std::vector<int> VectorOfInts;
        static std::vector<char> StaticVectorOfChars;

    public:
        bool operator < (const MyClass > c) const
        {
            return VectorOfInts < c. VectorOfInts;
        }
        bool operator == (const MyClass > c) const
        {
            return VectorOfInts == c. VectorOfInts;
        }
    };

    // Instantiate the class vector<MyClass>
    // This does not create an object. It only forces the generation of
    // all of the members of the class vector<MyClass>. It exports them
    // from the DLL and imports them into the .exe file.
    EXPIMP_TEMPLATE template class DECLSPECIFIER std::vector<MyClass>;

    // -------------------------------------------
    // Compile options needed: /GX /LDd /MDd /D"EXP_STL"
    //                     or: /GX /LD  /MD  /D"EXP_STL"
    // DLL.CPP

    #include "MyHeader.h"
    std::vector<char> MyClass::StaticVectorOfChars;

    // -------------------------------------------
    // Compile options needed: /GX /MDd
    //                     or: /GX /MD
    // EXE.CPP

    #include <iostream>
    #include "MyHeader.h"

    int main ()
    {
        MyClass x;

        for (int i=0; i<5; i++) x.VectorOfInts.push_back(i);
        for (char j=0; j<5; j++) x.StaticVectorOfChars.push_back('a' + j);

        std::vector<int>::iterator vii = x.VectorOfInts.begin();
        while (vii != x.VectorOfInts.end())
        {
            std::cout << *vii;
            std::cout << " displayed from x.VectorOfInts" << std::endl;
            vii++;
        }
        std::vector<char>::iterator vci = x.StaticVectorOfChars.begin();
        while (vci != x.StaticVectorOfChars.end())
        {
            std::cout << *vci;
            std::cout << " displayed from MyClass::StaticVectorOfChars";
            std::cout << std::endl;
            vci++;
        }

        std::vector<MyClass> vy;
        for (i=0; i=5; i++) vy.push_back(MyClass());

        return 1;
    }
				

??????

???????? ??????? ?? ??? ????? C++ ??? ??? ????? ???? ?? ?????:
?????? Instantiation
__declspec
?????
/ MD, ML, /MT, /LD (????? ??-???? ?????????)

???

???? ID: 168958 - ????? ???????: 02 ?????? 2010 - ??????: 4.0
???? ???? ???? ??:
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
??????: 
kbstl kbinfo kbcode kbhowto kbmt KB168958 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:168958

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com