Using third-party classes in a C ++ header file

Suppose there is a third-party class with a name (including a namespace) other::OtherClass.

And this is the header file.

class MyClass {
  public:
    ...
  private:
    other::OtherClass other_class_;
    ...
}

If this header file was sent to production, would it be considered as providing an implementation to the client?

On the other hand, is it a good idea or not to use a third-party class in an open interface? (Note that this second example does not necessarily save this class as a private member.)

class MyClass {
  public:
    MyClass(const other::OtherClass& other_class);
    ...
  private:
    ...
}

In the first example, the client must know the size other::OtherClassand include the header file. In the second example, the client should be able to create other::OtherClass, which may also need a header file if the factory was not provided.

?

, , ?

+3
2

, .

, . - factory , .

, , :

class other::OtherClass;

, . .

+2

. .

, .

/ , .

0

All Articles