c++ - 友元函数返回 (void*) : cannot get implementation in . cpp 文件工作

标签 c++ gcc friend void-pointers

这是我的代码的快捷方式:

//myClass.h
namespace toto
{
  class myClass
  {
    friend void *myRoutine(void*);
    private:
      char* _name;
  }
}

//myClass.cpp
using namespace toto;
void *myRoutine(void* arg)
{
  myClass* foo = static_cast<myClass*>(arg);
  if ( NULL != foo )
  {
    cout << foo->_name;
  }
}

使用 GCC 编译时,出现错误“_name is private”。我绝对需要那个函数签名,因为它被用作线程例程。而且我想避免将我的属性更改为 public..

如果有人能帮助我,谢谢!

编辑:另外,myClass 是在命名空间中定义的,在 .cpp 文件中我在开头放置了“using namespace ...”。

最佳答案

您在 myClass 中的友元声明声明了一个 toto::myRoutine,而您的函数定义则定义了一个 ::myRoutine。在与 myClass 相同的命名空间中定义 myRoutine 以解决您的问题。

关于c++ - 友元函数返回 (void*) : cannot get implementation in . cpp 文件工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17673101/

相关文章:

c++ - 定义 ostream 运算符的友元函数

c++ - 类模板中的好友成员函数定义

c++ - 指示 Qi 转换属性失败的正确方法是什么?

c++ - 无序映射相等功能 c++

c++ - :C++: Exposing specialized templates only

gcc - 帮助在雪豹 : command '/usr/bin/gcc-4.0' failed with exit status 1 上安装 psycopg2

c - 忽略一个特定文件的错误

c++ - 在OpenCV中找到两个梯形的相交面积

c - libc.a 包含哪些标准库函数?

history - Foursquare - friend 的签到历史记录?