+ -
当前位置:首页 → 问答吧 → 关于颜色打印输出的问题,求解答

关于颜色打印输出的问题,求解答

时间:2011-12-26

来源:互联网

我想重新写一个关于打印颜色的接口,我是如此调用的:
抽象了一个类大致如下

全局变量已经定义在global.h里了
包括hOut

class Api_arithmetic
{
public:
....
...
  const void print() const;
private:
...
  void setColor(WORD color);
};
......
.........................
void Api_arithmetic::setColor(WORD color)
{
  SetConsoleTextAttribute(hOut,color);
}

const void Api_arithmetic::print() const
{
  setColor(FOREGROUND_RED);
  cout<<"TEST"<<endl;
}


'Api_arithmetic::setColor' : cannot convert 'this' pointer from 'const Api_arithmetic' to 'Api_arithmetic &'
编译时会有如此错误?为什么呢?不明白~求高手解答~

作者: judymac   发布时间: 2011-12-26

const void Api_arithmetic::print() const
-----
把前后的const去掉。
头文件也同步下。

或者,用const_cast转换成非const的this指针。

作者: Loaden   发布时间: 2011-12-27