0

I tried to search solution for this problem, but I could not find any. This is my class:

class X;
class MyClass
{
  public:
    MyClass();

  protected:
    // ctor for unit test
    MyClass(std::shared_ptr<X> p_x);
};

In unit test:

class FakeClass : public MyClass
{
  public:
    using MyClass::MyClass;
};

In the tests I want to use it:

FakeClass myFake(std::shared_ptr<X>(new X));

But g++ says:

MyClass::MyClass(std::shared_ptr) is protected

How can be specified the exact method for using?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
titapo
  • 135
  • 11

1 Answers1

1

FakeClass can use the MyClass constructor, but wherever you're constructing your FakeClass from can't - it's not a friend or a derived type.

You'll have to write a public FakeClass constructor, and that has to be what's calling the MyClass protected constructor:

FakeClass(std::shared_ptr<X> p)
: MyClass(p)
{ }
Barry
  • 286,269
  • 29
  • 621
  • 977