Search code examples
c++11stlforward-declaration

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!


Solution

  • 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.