Opaque pointer With Class Constructor

半腔热情 提交于 2019-12-25 02:07:57

问题


I need to create some variable defined in class source private to that class only. I am not able to move this variable to class header because of some other header file issue. I found this page http://en.wikipedia.org/wiki/Opaque_pointer and explains how it can achieve,

Here is my class source

struct testClass::testStruct {
    int a;
    int b;
    boost::asio::io_service io_service_2;
    client c_3(io_service_2); // this is another class, getting error here
};

testClass::testClass(): test(new testStruct())
{
// do something
}

class header

class testClass
{
public:
    testClass();
    ~testClass();

private:
    struct testStruct;               
    testStruct* test;               
};

While compile the I am getting the error

 error: C2061: syntax error : identifier 'io_service_2'

Actually client is another class which I previously initialized as global

client c_3(io_service_2);

Now I cannot use it as global, I need to make it as private to the class, so choose above method.

Note: I cannot define client c_3 as class variable in class header because of some header issue. How can I resolve this issue?.

Thanks Haris

来源:https://stackoverflow.com/questions/30420182/opaque-pointer-with-class-constructor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!