我在C++的类和对象中,在那里我很难理解类的减速概念,为此我编写了一个不编译的小程序,任何人都会指导我?如何从C++中的类开始
#include <iostream>
using namespace std;
class myClass{
friend increment(myClass, int);
private:
int topSecret;
public:
myClass(){
topSecret = 100;
}
void display(){
cout<<"The value of top Secter is"<<topSecret;
}
};
void increment(myClass A, int i){
A.topSecret += i;
}
int main() {
myClass x;
x.display();
increment(x,10);
x.display();
}
'朋友无效增量( myClass,int);'<< ** void ** – user657267 2015-02-12 09:02:29
是否需要声明返回类型的好友函数? @ user657267 – Bilal 2015-02-12 09:05:30
你应该编写'getter()'和'setter()'函数来访问你的私有成员'topSecret'。 – Aleph0 2015-02-12 09:05:34