Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;_C++_Class_Constructor_Private_Friend - Fatal编程技术网

C++ c++;

C++ c++;,c++,class,constructor,private,friend,C++,Class,Constructor,Private,Friend,我只是不明白,这个朋友声明有什么问题,第一个错误消息: test.cpp: In function 'int main()': test.cpp:34:7: error: 'void steuerung::exe_testa(testa)' is private test.cpp:48:15: error: within this context 当testa的类声明中的构造函数被删除时,问题就解决了。但我需要一个构造函数。有人能帮我吗?真的谢谢你 #include <iostream&

我只是不明白,这个朋友声明有什么问题,第一个错误消息:

test.cpp: In function 'int main()':
test.cpp:34:7: error: 'void steuerung::exe_testa(testa)' is private
test.cpp:48:15: error: within this context
当testa的类声明中的构造函数被删除时,问题就解决了。但我需要一个构造函数。有人能帮我吗?真的谢谢你

#include <iostream>

class steuerung;
class testb;
class testa;

class testa
{
friend class steuerung;
public:

private:
double a_;
double b_;
};

class testb
{
friend class steuerung; 
public:
testb(double a, double b) : a_(a), b_(b) {}

private:
double a_;
double b_;
};

class steuerung
{
friend class testa; 
friend class testb; 
void exe_testa(testa t_) { t_.b_++; }
//template<class t> void exe(t *t_) { std::cout << t_->a_ << std::endl; }
};




int main ()
{
std::cout << "Laeuft zumindest an.." << std::endl;

testa a;

steuerung s;
s.exe_testa(a);

return 0;
}
#包括
steuerung类;
testb类;
种皮类;
类种皮
{
朋友班;
公众:
私人:
双a;
双b_;
};
类testb
{
朋友班;
公众:
testb(double a,double b):a_u(a),b_u(b){}
私人:
双a;
双b_;
};
斯特隆班
{
朋友类遗嘱;
朋友类testb;
void exe_testa(testa t_{t_.b_++}

//模板void exe(t*t_3;){std::cout a
exe\u testa
是私有的,因此只能从
steuerung
的成员函数、属于
steuerung
之友的类的成员函数以及
steuerung
main
的朋友函数调用,因此调用是非法的。

exe\u testa
是私有的,因此只能从
steuerung
的成员函数调用,类的成员函数是
steuerung
的朋友,而
steuerung
main
的朋友函数都不是,所以调用是不合法的。

Argh该死的,没有想到这一点。我假设类成员默认是公共的。。谢谢你!@user1456766-对。类的默认访问权限是私有的;结构的默认访问权限是公共的。啊,该死的,我没想到。我假设类成员默认是公共的。谢谢!@user1456766-对。类的默认访问权限是私有的;结构的默认访问权限是公共的。