简体   繁体   中英

C++: typedefing and nested class issue

I have:

class ThreadPool
{
public:
    ....
private:
    struct TP_Thread: public Thread_t
    {
        ....
    };
    std::vector<std::tr1::shared_ptr<TP_Thread> >   m_threads;
   .....
};

I wanna do something like:

typedef std::tr1::shared_ptr<TP_Thread> shpThread;

to shorten the writing in the class definitions. Problem is I either get pointer to incomplete type (because of forward declaration before the class and typedef the public section) or trying to access a private member of ThreadPool (in the case I'm trying to typedef it outside the class). How can I typedef this so I can use it freely during implementations?

Why not including your typedef in a public section of the class:

class ThreadPool
{
public:
    ....
private:
    struct TP_Thread: public Thread_t
    {
        ....
    };
public:
    typedef std::tr1::shared_ptr<TP_Thread> Shp;
    ...

then use ThreadPool::Shp in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM