假设我有一个std::vectorof std::strings。
// Foo.h
class Foo {
std::vector< std::string > mVectorOfFiles;
}
然后我typedef把它变成了一个StringVector类型。
// Foo.h
typedef std::vector< std::string > StringVector;
class Foo {
StringVector mVectorOfFiles;
}
如果我有另一个需要一个StringVector对象的类......
// Bar.h
class Bar {
Bar( const StringVector & pVectorOfFiles ); // I assume this produces a compile error (?) since Bar has no idea what a StringVector is
}
...我必须typedef在头文件中再次使用Bar吗?
// Bar.h
typedef std::string< std::vector > StringVector;
class Bar {
Bar( StringVector pListOfFiles );
}
是否可以将其typedef std::vector< std::string > StringVector放在一个文件中并让其他所有类都知道该类型StringVector?