为什么c++对象映射在Mavericks和Mountain Lion上不同?
Why do C++ Maps of Objects differ on Mavericks and Mountain Lion
我有一个问题,归结为以下内容:
我有一个c++结构,其中包含一个向量
struct Structure{
std::vector<int> c;
Structure();
Structure(std::vector<int> c_init);
};
Structure::Structure( std::vector<int> c_init)
{c= c_init;
}
Structure::Structure(){
}
和下面的程序
#include <iostream>
#include <vector>
#include <map>
#include "structr.h"
using namespace std;
int main () {
map<int, Structure*> StructureMap;
vector<int> foo;
foo.push_back(39);
foo.push_back(70);
foo.push_back(72);
StructureMap[1]=new Structure( foo);
cout << (*StructureMap[1]).c[0] << "n" ;
return 0;
}
用g++编译,输出是Mavericks和Mountain Lion上的"39",正如我假设的那样。但是,如果我在Mavericks上使用lldb逐步执行程序,我将收到
20 StructureMap[1]=new Structure( foo);
21
-> 22 cout << (*StructureMap[1]).c[0] << "n" ;
23
24 return 0;
25 }
(lldb) p *StructureMap[1]
(Structure) $6 = {
c = size=3 {
[0] = 39
[1] = 70
[2] = 72
}
}
在Mountain Lion上我得到
19 foo.push_back(72);
20 StructureMap[1]=new Structure( foo);
21
-> 22 cout << (*StructureMap[1]).c[0] << "n" ;
23
24 return 0;
25 }
(lldb) p *StructureMap[1]
error: call to a function 'std::map<int,Structure*,std::less<int>,std::allocator<std::pair<const int, Structure*> > >::operator[](int const&)' that is not present in the target
error: Couldn't materialize struct: Structure hasn't been laid out yet
(lldb)
为什么地图没有正确填写山狮,更让我困惑的是,为什么输出仍然是"39",即使地图是空的?
Thanks a million - Rob
映射被正确填充,如39
所示的结果。从你的错误信息来看,Mountain Lion的lldb
不理解Structure
类型。这与地图本身无关。
这并不太令人惊讶。编写好的调试器是很困难的,正如Wikipedia所说"LLDB还处于早期开发阶段"
相关文章:
- 在Mac OS X Mountain Lion(或更高版本)和Linux上使用X11/Xlib.h
- Qt 5.0 and c++11 with OSX Mountain Lion
- gem 安装 unf_ext -v '0.0.6' 在 Mountain Lion Mac 上失败
- 编译 PyGAMMA Mac Lion:g++ 找不到标准的 C++ 头文件(字符串/iostream..)
- 为什么当我键入名称时我的可执行文件不会运行?(Mac OS X Mountain Lion)Mac OS X 10.8.
- 如何在Mac OS X Mountain Lio上编译libnoise
- OpenMP Mac OSX Lion c++ 链接器错误 体系结构的未定义符号 x86_64:"_omp_get_thread_num"
- Macports GCC 4.8无法链接OSX Lion上的c++库
- Using g++ on OSX Lion, ld: unknown option: -no_compact_unwin
- NPM 模块画布需要的在 OSX Mountain Lion 上安装 c++ 库的过程是什么?
- Simplecrypt让我的QT应用程序在OS X Mountain Lion上崩溃,但在Windows上完美运行
- 安装 opencv 时出错,我正在使用 lion 和 xcode4.4
- 带有 Mountain Lion 的 g++ 是否支持 -msse4.2
- ::CFBundleLoadExecutable 无法加载已编译的捆绑包(Mountain Lion,Xcode 4.6
- HMAC on Mountain lion OSX 10.8.3 EXC_CRASH
- SublimeClang OSX Mountain Lion C++11
- 为什么c++对象映射在Mavericks和Mountain Lion上不同?
- MacOS Mountain Lion上架构x86_64的未定义符号
- 是否可以在Mountain Lion上的当前Xcode 4.6.1工具链中启用_LIBCPP_DEBUG2
- Mountain Lion上的Mex文件:显式实例化错误