Opaque pointer With Class Constructor

2019-09-01 09:55发布

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

标签: c++ class
0条回答
登录 后发表回答