刚学c++,遇到有关问题请大神指点哪错了。多谢
刚学c++,遇到问题请大神指点哪错了。谢谢
#include<iostream>
using namespace std;
class A
{
public:
void get(){x=3,y=4,z=5;}
int x;
int fun2(){return z;}
protected:
int y;
private:
int z;
};
class B:public A
{
public:
int fun1(){return y;}
};
void main()
{
B b;
b.get();
cout<<b.x<<endl;
b.fun1();
cout<<b.fun1<<endl;
b.fun2();
cout<<b.fun2<<endl;
}
------解决思路----------------------
------解决思路----------------------
cout<<b.fun1<<endl;
fun1是函数不是成员变量啊
------解决思路----------------------
函数调用得使用()
#include<iostream>
using namespace std;
class A
{
public:
void get(){x=3,y=4,z=5;}
int x;
int fun2(){return z;}
protected:
int y;
private:
int z;
};
class B:public A
{
public:
int fun1(){return y;}
};
void main()
{
B b;
b.get();
cout<<b.x<<endl;
b.fun1();
cout<<b.fun1<<endl;
b.fun2();
cout<<b.fun2<<endl;
}
------解决思路----------------------
#include <iostream>
#include <cstdio>
using namespace std;
class A
{
public:
void get(){x=3,y=4,z=5;}
int x;
int fun2(){return z;}
protected:
int y;
private:
int z;
};
class B:public A
{
public:
int fun1(){return y;}
};
int main(int argc, char *argv[])
{
B b;
b.get();
cout<<b.x<<endl;
b.fun1();
b.fun2();
printf("%p\n", &B::fun1);
printf("%p\n", &B::fun2);
return 0;
}
------解决思路----------------------
cout<<b.fun1<<endl;
fun1是函数不是成员变量啊
------解决思路----------------------
函数调用得使用()
cout << b.fun1() << endl;
cout << b.fun2() << endl;