构造函数重载引起“转换到非标量类型”的问题!

[复制链接]
查看11 | 回复1 | 2009-5-5 10:34:30 | 显示全部楼层 |阅读模式
按如下方式声明一个类:
class MystarDictInfo{
public:
MystarDictInfo() {};
~MystarDictInfo() {};
/* overload */
MystarDictInfo(const std::string filename);
std::string idxName;
std::string ifoName;
std::string dzName;
std::string libName;
};
可是在一个函数R中想将其实例化时:
MystarDictInfo star_info = new MystarDictInfo(filename);
其中filename是R的一个参数,并且也是const string类型的。
主要是想调用不同的构造函数来初始化对象而已!
这时出现“ 请求从"MystarDictInfo*"转换到非标量类型"MystarDictInfo"” 这样的错误!
这是怎么回事呢?

回复

使用道具 举报

千问 | 2009-5-5 10:34:30 | 显示全部楼层
new的返回值是相应类的指针类型啊,要用MystarDictInfo *star_info=new MystarDictInfo(filename);...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行