无法在托管 C++ 中使用 new 关键字创建非托管对象
我创建了一个以 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
有人可以向我解释一下吗? 谢谢。
I've created a class with a boost::unordered_map as a member,
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
and in the managed side of C++,
I try to create the pointer of the obj:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
Linkage* m_pLink = new Linkage();
.....
}
However this produces errors:
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
Could anyone explain to me pls?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终,当我在构造函数中显式实例化它时,它就起作用了:
Eventually this works when I explicitly instantiate it inside the constructor: