C++代码求助,在VC++6.0上编

来源:百度知道 编辑:UC知道 时间:2024/05/09 07:21:27
//Header file newClock.h
#ifndef H_newClock
#define H_newClock
#include <iostream>
using namespace std;
class clockType
{ friend ostream& operator << (ostream&, const clockType&);
friend istream& operator >> (istream&, clockType&);
public:
void setTime(int hours, int minutes, int seconds);
void getTime(int& hours, int& minutes, int& seconds) const;
clockType operator++();
bool operator==(const clockType& otherClock) const;
bool operator<=(const clockType& otherClock) const;
clockType(int hours = 0, int minutes = 0, int seconds = 0);
private:
int hr; int min; int sec;
};
#endif
//Implementation file newClock.cpp
#include <iostream>
#include "newClock.h"
using namespace std;
clockType clockType::operator++()
{ sec++;
if (sec > 59)
{ sec = 0; min++;

很明显min,hr,sec都是私有数据成员,似有数据成员是不能直接由实例访问的。要么把他们都声明成public,要么写调用接口。就可以了

class clockType
{
// private:
int hr; int min; int sec;
}
注释掉就好了

class clockType
{
public: //此处修改
int hr; int min; int sec;
}

这是基本语法错误,在哪个编译器上运行都会出这个错的。错误理由就是楼上所说的