-3
#include "stdafx.h"                            //In order to use Visual C++

#include <iostream>
#include <Loki\SmallObj.h>                    //The header file to manage
                                              // smalls objects allocator

class MySmallObj : public Loki::SmallObjAllocator    //inherit from the base
                                                     //class SmallObjAllocator 
{
public:
    MySmallObj():SmallObjAllocator(sizeof(char), sizeof(long),0){};
};

int _tmain(int argc, _TCHAR* argv[])
{
    MySmallObj * premier = new MySmallObj;                                                      //declaring my object derived from smallobjallcator
    char * myChar = static_cast<char*>( premier->Allocate(1, true));            //calling allocate from my object and conveting the void pointer to char*
    premier.Deallocate(myChar, 1);

    return 0;
}

loki ライブラリは、本質的に C++ でジェネリック プログラミングを使用します。メモリのスモール オブジェクト アロケータ (Loki::SmallObjAllocator) を使用してコードを作成しました。Visual C++ 2010 を使用しています。

私はそれらのエラーを受け取ります:

  >  MyLoki.cpp
1>MyLoki.obj : error LNK2019: unresolved external symbol "public: void __thiscall Loki::SmallObjAllocator::Deallocate(void *,unsigned int)" (?Deallocate@SmallObjAllocator@Loki@@QAEXPAXI@Z) referenced in function _wmain
1>MyLoki.obj : error LNK2019: unresolved external symbol "public: void * __thiscall Loki::SmallObjAllocator::Allocate(unsigned int,bool)" (?Allocate@SmallObjAllocator@Loki@@QAEPAXI_N@Z) referenced in function _wmain
1>MyLoki.obj : error LNK2019: unresolved external symbol "protected: __thiscall Loki::SmallObjAllocator::SmallObjAllocator(unsigned int,unsigned int,unsigned int)" (??0SmallObjAllocator@Loki@@IAE@III@Z) referenced in function "public: __thiscall MySmallObj::MySmallObj(void)" (??0MySmallObj@@QAE@XZ)
4

1 に答える 1

0

私は最初の質問に対する答えを確立しました。

#include "stdafx.h"                            //In order to use Visual C++

#include <iostream>
#include <Loki\SmallObj.h>                    //The header file to manage
                                              // smalls objects allocator

class MySmallObj : public Loki::SmallObjAllocator    //inherit from the base
                                                     //class SmallObjAllocator
{
public:
    MySmallObj():SmallObjAllocator(sizeof(char), sizeof(long),1){};  //the chunkSize < maxObjsize
};
int _tmain(int argc, _TCHAR* argv[])
{
    MySmallObj * premier = new MySmallObj;                                                      //declaring my object derived from smallobjallcator
    char * myChar = static_cast<char*>( premier->Allocate(1, true));            //calling allocate from my object and conveting the void pointer to char*
    premier->Deallocate(myChar, 1);

    return 0;
}

複数のエラー

未解決の外部シンボル

プロジェクトに含まれていなかった Loki の SmallObj.cpp が原因です。

たとえば、Loki::SmallObjAllocator、Loki::SmallObjectはこちら

于 2015-05-24T23:06:33.977 に答える