急,急,高分求助。VC++ .NET 中 我用 DictionaryBase 为基类派生我的类在属性Item中的问题,

new_stranger 2003-06-30 11:57:16
//.h文件
#pragma once
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;

__gc class DictionaryInheritor : public DictionaryBase
{
public:

DictionaryInheritor(void);

~DictionaryInheritor(void);

__property String * get_Item(String * key);

__property void set_Item(String * key, String * value);

};

//.cpp文件
#include "StdAfx.h"
#include "dictionaryinheritor.h"


DictionaryInheritor::DictionaryInheritor(void)
{

}


DictionaryInheritor::~DictionaryInheritor(void)
{

}


String * DictionaryInheritor::get_Item(String * key)
{
String * strResult = "hello!";
return strResult;
}


void DictionaryInheritor::set_Item(String * key, String * value)
{

}

输出错误:
error C3815: “DictionaryInheritor::get_Item”方法的返回类型必须与
“System::Collections::IDictionary::set_Item”最后一个参数的类型匹配
如果将get_Item的返回类型改为Object * set_Item 的最后一个参数改为Objiect,则可顺利通过编译。

why?????

...全文
42 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
new_stranger 2003-06-30
  • 打赏
  • 举报
回复
在线waiting
new_stranger 2003-06-30
  • 打赏
  • 举报
回复
关注!
new_stranger 2003-06-30
  • 打赏
  • 举报
回复
up
new_stranger 2003-06-30
  • 打赏
  • 举报
回复
up
lostinetdotcom 2003-06-30
  • 打赏
  • 举报
回复
我这里没有vc.net,帮不到你了。~~
new_stranger 2003-06-30
  • 打赏
  • 举报
回复
谢谢
lostinetdotcom 2003-06-30
  • 打赏
  • 举报
回复
。。。
例如:
//.h文件
#pragma once
#using <mscorlib.dll>
using namespace System;
using namespace System::Collections;

__gc class DictionaryInheritor : public DictionaryBase
{
public:

DictionaryInheritor(void);

~DictionaryInheritor(void);

__property Object * get_Item(Object * key);
__property void set_Item(Object * key, Object * value);
__property String * get_Item(String * key);
__property void set_Item(String * key, String * value);


};


//.cpp文件
#include "StdAfx.h"
#include "dictionaryinheritor.h"


DictionaryInheritor::DictionaryInheritor(void)
{

}


DictionaryInheritor::~DictionaryInheritor(void)
{

}

Object* DictionaryInheritor::get_Item(Object* key)
{
return get_Dictionary().get_Item(key);
}


void DictionaryInheritor::set_Item(Object* key, Object* value)
{
return get_Dictionary().set_Item(key,value);
}

String * DictionaryInheritor::get_Item(String * key)
{
return (String*)get_Dictionary().get_Item(key);
}


void DictionaryInheritor::set_Item(String * key, String * value)
{
return get_Dictionary().set_Item(key,value);
}
new_stranger 2003-06-30
  • 打赏
  • 举报
回复
可不可以在明示一二?
lostinetdotcom 2003-06-30
  • 打赏
  • 举报
回复
必须先实现
IDictionary::Item

---
也就是说,
__property Object * get_Item(Object * key);
__property void set_Item(Object * key, Object * value);
__property String * get_Item(String * key);
__property void set_Item(String * key, String * value);
这两个属性要同时做。

7,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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