关于Visual Studio C4700错误,这段代码中的错误是什么? [英] About Visual Studio C4700 error,what is the error in this code??

查看:402
本文介绍了关于Visual Studio C4700错误,这段代码中的错误是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< iostream>

使用命名空间std;

class abc

{

private:

int x;

public:

friend void man(abc);

void seta();

};
$
void abc :: seta()

{

x = 3;

cout<< x;

}

b级:公共abc

{

受保护:

int y;

public:

void setb();

};

void b :: setb()

{

y = 2;

cout<< y;

}

int main()

{

abc obj;

bf;

f.seta();

f.setb();

man(obj);

system( "暂停");

}

无效人(abc g)

{

gx = 2;

cout<< gx;

}

#include <iostream>
using namespace std;
class abc
{
private:
int x;
public:
friend void man(abc);
void seta();
};
void abc::seta()
{
x = 3;
cout << x;
}
class b:public abc
{
protected:
int y;
public:
void setb();
};
void b::setb()
{
y = 2;
cout << y;
}
int main()
{
abc obj;
b f;
f.seta();
f.setb();
man(obj);
system("pause");
}
void man(abc g)
{
g.x = 2;
cout << g.x;
}

推荐答案

类abc有一个私有成员(int x)但是类没有有一个构造函数。 那么在构造期间如何初始化成员x?

class abc has a private member (int x) but the class does not have a constructor.  So how is member x initialized during construction?

另外,请注意您将obj的副本传递给man()函数。 当man()返回时,obj的私有x成员中包含的原始值将保持不变。

Also, notice that you are passing a copy of obj to the man() function.  When man() returns, the original value contained in the private x member of obj will be unchanged.


这篇关于关于Visual Studio C4700错误,这段代码中的错误是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆