map>.

xuegao007 2008-06-13 03:03:19
我想这样用map<int, CArray<int, int&>>.
但在insert时提示错误
error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
1> d:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(553) : see declaration of 'CObject::CObject'
1> d:\program files\microsoft visual studio 8\vc\atlmfc\include\afx.h(524) : see declaration of 'CObject'

map<int, CArray<int, int&>> m;
typedef pair <CString, CArray<int, int&>> Str_IntAry;
m.insert( Str_IntAry("csdn", ary) );


请大家帮我分析下。
...全文
213 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gob00st 2008-07-01
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 yuzl32 的回复:]
无满意答案结贴 直接对楼主无语..
[/Quote]
yuzl32 2008-06-14
  • 打赏
  • 举报
回复
无满意答案结贴 直接对楼主无语..
yuzl32 2008-06-13
  • 打赏
  • 举报
回复
另外lz既用到mfc静态链接库,又用到c运行时库,可能会出现冲突.
yuzl32 2008-06-13
  • 打赏
  • 举报
回复
看样子map的insert,会复制CArray然后把复制的对象插入map,而CArray没有实现拷贝构造函数和operator=,所以会调用CObject的,而CObject的是private因此出错.
Gob00st 2008-06-13
  • 打赏
  • 举报
回复
1>你要明白map中寸的是副本,所以你想要存的object需要支持拷贝构造函数;
2>而你看看CSND就知道CArray的共有接口中没有贝构造;
所以才会报错。

建议楼主可能的话,在这里使用vector替代CArray。
jieao111 2008-06-13
  • 打赏
  • 举报
回复
没用过CArray
leelittlelong 2008-06-13
  • 打赏
  • 举报
回复
用make_pair
leelittlelong 2008-06-13
  • 打赏
  • 举报
回复
m.insert( Str_IntAry("csdn", ary) );

不能这么用。
Maxwell 2008-06-13
  • 打赏
  • 举报
回复
map <int, CArray <int, int&>> m;
typedef pair <CString, CArray <int, int&>> Str_IntAry;
m.insert( Str_IntAry("csdn", ary) );
pair的类型就跟map不一致。。。

记得CArray在VC6中缺少复制构造函数和赋值运算符重载,不能用在map中。
taodm 2008-06-13
  • 打赏
  • 举报
回复
您既然用map了,那就用vector,别混用CArray了。
xuegao007 2008-06-13
  • 打赏
  • 举报
回复
vs2005控制台下的程序:
#include "stdafx.h"
// map_find.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
#include <afxtempl.h>
using namespace std;

int main( )
{
using namespace std;
typedef pair<int, CArray<int, int> > Int_pInt;

CArray<int, int> ary;
ary.Add( 1 );
ary.Add( 10 );
ary.Add( 100 );
map<int, CArray<int, int> > m;

Int_pInt myint;
myint.first = 1;
myint.second.Copy( ary );

m.insert( myint );


}
编译不过。????????????????
cppscript 2008-06-13
  • 打赏
  • 举报
回复
cannot access private member declared in class 'CObject'
不能访问私有对象

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧