0

I just don't get it, what is wrong in this friend declaration, first error msg:

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

The problem is being solved, when the constructor in testa's class declaration is removed. But I need a constructor. Can anyone please help me? Really thank YOU.

#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;
}

1 Answers1

4

exe_testa is private, so can only be called from member functions of steuerung, member functions of classes that are friends of steuerung, and friend functions of steuerung. main is none of those, so the call isn't legal.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165