Help: a simple C++ issue!

GoogleGeek 2005-06-09 11:54:00
很久不用C++了,连语法都忘的差不多了,汗.........

//这样进行参数声明是什么意思? "const smartAV::Current &"
virtual void printString(const string & s,const smartAV::Current &);

Thanks

//----------------------------------------------------

#include <iostream>
//declare Printer class
#include <Printer.h>
//declare smartAV class
#include <smartAV.h>
using namespace std;

class PrinterI : public Printer {
public:virtual void printString(const string & s,const smartAV::Current &);
};

//这样进行参数声明是什么意思? "const smartAV::Current &"
void PrinterI::printString(const string & s, const smartAV::Current &)
{
cout << s << endl;
}

第一个参数是s,第二参数是什么呢?在我眼中认为第二个参数不存在

但是编译却没有任何问题,为什么?
...全文
135 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
foochow 2005-06-09
  • 打赏
  • 举报
回复
学习学习
whyglinux 2005-06-09
  • 打赏
  • 举报
回复
smartAV是一个类,Current是在这个类中定义的一个类型别名,所以要用 smartAV::Current 来表示。

C/C++标准允许在函数声明中存在没有在函数体中用到的函数参数。没有用到的函数参数也可以省略其参数名。
GoogleGeek 2005-06-09
  • 打赏
  • 举报
回复
是存在smartAV的namespace!
但问题是:
void PrinterI::printString(const string & s, const smartAV::Current &)
{
cout << s << endl;
}
参数声明中:
const smartAV::Current &
应该是定义一个Current类型的引用吧?但是这个引用却没有名字?
我知道在声明函数时,可以省掉具体的参数名,只要写参数类型 进行占位就行了,但是在实现时还是要写参数名字的!
「已注销」 2005-06-09
  • 打赏
  • 举报
回复
存在smartAV命名空间
积木 2005-06-09
  • 打赏
  • 举报
回复
你去看看头文件的定义是不是有smartAV这么一个名字空间
guyaguya 2005-06-09
  • 打赏
  • 举报
回复
UPInt& UPInt::operator++()
{
*this += 1; // 增加
return *this; // 取回值
}

// postfix form: fetch and 自增
const UPInt UPInt::operator++(int)
{
UPInt oldValue = *this; // 取回值
++(*this); // 增加

return oldValue; // 返回被取回的值
}

这个int 就是用来区分而没有使用,所以可以不用参数名。
zeeeitch 2005-06-09
  • 打赏
  • 举报
回复
使用重载实现某些功能
积木 2005-06-09
  • 打赏
  • 举报
回复
不过如果你在函数里面用到了这个形参,你自然需要一个参数名字了

这种手法也可以理解成一种类似于模板的手法……
MagicCarmack 2005-06-09
  • 打赏
  • 举报
回复
C/C++标准允许在函数声明中存在没有在函数体中用到的函数参数。没有用到的函数参数也可以省略其参数名。


--------------

此君所言即是

64,648

社区成员

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

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