无法使用托管C ++中的新关键字创建非托管对象

时间:2010-05-21 00:59:43

标签: c++ boost object unmanaged managed

我创建了一个以boost :: unordered_map为成员的类,

Linkage.h

#ifndef LINKAGE_H
#define LINKAGE_H

#include <boost/unordered_map.hpp>

class Linkage
{
private:
    boost::unordered_map<int, int> m_IOMap;
public:
         ....
};

Linkage.cpp

#include "stdafx.h"

... // methods

并且在C ++的托管方面, 我尝试创建obj的指针:

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    Linkage* m_pLink = new Linkage();
         .....
}

然而,这会产生错误:

Error   4   error LNK2005: "private: static unsigned int const boost::detail::type_with_alignment_imp<4>::found" (?found@?$type_with_alignment_imp@$03@detail@boost@@$$Q0IB) already defined in Proj_Test.obj   Linkage.obj
.....
Error   7   fatal error LNK1169: one or more multiply defined symbols found

有人可以向我解释一下吗? 感谢。

1 个答案:

答案 0 :(得分:0)

最后,当我在构造函数中显式实例化它时,它会起作用:

#include "stdafx.h"

Linkage::Linkage()
{
    template boost::unordered_map<int, int>;
}