访问仅在父级的cpp文件中的类

Pan*_*chi 0 c++

我想调用一个只在父源类文件的文件中的类.实际上我在4个文件中有3个类:

parent.h 
parent.cpp 
child.h
child.cpp
Run Code Online (Sandbox Code Playgroud)

"主要"类是ChildParent.该类Otherclass位于类的定义上方的parent.h文件中Parent.

如何才能访问Otherclass仅在child.cpp文件的parent.cpp文件中的类?

(不幸的是,我不允许在父文件中进行大的更改.)

parent.cpp:

using ParentNamespace::Parent;


namespace other
{
    class Otherclass
    {
    public:
        Otherclass()
        {
            // do something
        }

        ~Otherclass()
        {
        }
    };
}


Parent::Parent()...
...
// here the Parent class continues normal
Run Code Online (Sandbox Code Playgroud)

child.cpp:

#include "parent.h"

Child::Child() :
ParentNamespace::Parent()
...
...
...
    // here I want to use Otherclass
Run Code Online (Sandbox Code Playgroud)

Lig*_*ica 6

我怎样才能访问'Otherclass'类,它只在child.cpp文件的parent.cpp文件中?

你不能.这是头文件的全部目的.使用它们.

(不幸的是,我不允许在父文件中进行大的更改.)

无论是现有的代码是完全被打破,你应该利用这一点来成为允许...

...或者这些是您应该以这种方式尝试使用的内部类.