Konstruktor przyjaciel

0

Czy konstruktor może być przyjacielem innej klasy jako funkcja ?

2
#include <iostream>
using namespace std;

class Foo{
friend class Bar;
	Foo(){}
};

struct Bar{
	void fizz(){
		Foo foo;
	}
};

int main() {
	Bar bar;
	bar.fizz();
	Foo foo;
	return 0;
}
3
struct foo;

struct bar {
  bar(foo& f);
  void buzz(foo& f);
};

struct foo {
  friend bar::bar(foo&);

private:
  int secret;
};

bar::bar(foo& f) { 
  f.secret = 10; // hłehłehle 
}

void bar::buzz(foo& f) {
  //f.secret = 10;  nope 
}

int main() {
  foo f;
  bar b(f);
  b.buzz(f);
  return 0;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1