Friend function from another namespace

  c++, friend-function
/** module.h */
#pragma once

class A {
  friend void helpers::logValue(const A &);
  int _val;

public:
  A() {}
};

namespace helpers {
  static void logValue(const A &a) {
    std::cout << a._val;  // <== ERROR: '_val' is not accessible
  }
}

How do I declare the friend function in another namespace?

Source: Windows Questions C++

LEAVE A COMMENT