c++ 内存的Loki的SmallObjAllocator

sdnqo3pr  于 2023-08-09  发布在  其他
关注(0)|答案(1)|浏览(93)
#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中的泛型编程,我使用内存的Small对象分配器(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)

3pmvbmvn

3pmvbmvn1#

我已经找到了第一个问题的答案。

#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;
}

字符串
多重误差
未解外部符号
是因为SmallObj.cpp,Loki没有包含在项目中
例如Loki::SmallObjAllocator,Loki::SmallObject here

相关问题