简体   繁体   中英

Including Header files in c++ of STL

I have a class Like this

/*class.h*/

class MClass
{
 public:
   MClass(std::vector<int> number);

}

And

/* class.cpp */
#include <vector>
#inclue "class.h"
MClass::MClass(std::vector<int> number)
{
  // Do Something
}

And it is not compiled if I do not add #include <vector> in the header file Is this behaviour normal or am I missing something?

You should include <vector> in your header. And then you should include your class's header in your cpp file.

You can't compile your cpp file without your class header. So it's normal to include your class header - there's no way around it. Also, it's normal to include only what is needed in your header so it doesn't introduce unnecessary dependencies in code that use your header. In this case, given your member function signature, you are required to include <vector> in your header.

class.cpp should #include "class.h"

class.h should #include <vector>

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