Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++11 forwarddeclare thread,mutex,chrono

I am aware that we should prefer to forward declare everything in header files, if possible but what about STL?

I have found that for iostream there is iosfwd.

What if i want to have a mutex declared in my class, like this:

class MyClass
{

.....
private:
    std::mutex mMutex;
};    

Should I include mutex header in my class header? Or is there way to forwarddeclare it, like:

class std::mutex;
class MyClass{...};

Same goes for chrono, and thread as well.

Any thoughts on that is appreacited. Thanks!

like image 764
Avi Avatar asked Dec 24 '14 22:12

Avi


1 Answers

There is no portable way to forward declare std::objects, except as specified (e.g. <iosfwd>). And there are no forwarding headers for mutex, thread or chrono.

like image 78
Howard Hinnant Avatar answered Nov 12 '22 21:11

Howard Hinnant