主题:[讨论]类的实现文件问题求助各位爱好者
请问各位高手这个类的实现文件中为何cerr和INT_MAX无法使用类的定义没有问题
#include<iostream>
#include"counter.h"
#include<climits>
using namespace std;
counter::counter()
{
count=0;
maxvalue=INT_MAX;
}
counter::counter(int mval)
{
count=0;
maxvalue=mval;
}
void counter::decrement()
{
if(count>0)
count--;
else
cerr<<"counter is out of range,decrement can not finish"<<endl;
}
void counter::increment()
{
if(count<MAX_INT)
count++;
else
cout<<"counter overflow,incrment ignore"<<endl;
}
void counter::setcounter(int val)
{
if(val>=0&&val<=maxvalue)
count=val;
else
cerr<<"new counter is out of range,value is not changed"<<endl;
}
void counter::setmaxvalue(int val)
{
if(val>=0&&val<=MAX_INT)
maxvalue=val;
else
cerr<<"new maxvalue is out of range,maxvalue is not changed."<<endl;
}
int counter::getcounter() const
{
return count;
}
int counter::getmaxvalue() const
{
return maxvalue;
}
#include<iostream>
#include"counter.h"
#include<climits>
using namespace std;
counter::counter()
{
count=0;
maxvalue=INT_MAX;
}
counter::counter(int mval)
{
count=0;
maxvalue=mval;
}
void counter::decrement()
{
if(count>0)
count--;
else
cerr<<"counter is out of range,decrement can not finish"<<endl;
}
void counter::increment()
{
if(count<MAX_INT)
count++;
else
cout<<"counter overflow,incrment ignore"<<endl;
}
void counter::setcounter(int val)
{
if(val>=0&&val<=maxvalue)
count=val;
else
cerr<<"new counter is out of range,value is not changed"<<endl;
}
void counter::setmaxvalue(int val)
{
if(val>=0&&val<=MAX_INT)
maxvalue=val;
else
cerr<<"new maxvalue is out of range,maxvalue is not changed."<<endl;
}
int counter::getcounter() const
{
return count;
}
int counter::getmaxvalue() const
{
return maxvalue;
}