Subclass problem: cannot access private member declared in parent class?

By default members of a C++ class are private so the constructor you declared in AClassA is private and cannot be called from AClassB. To call it from AClassB you need to make it public or protected, e.g.

public:
AClassA( const FObjectInitializer& ObjectInitializer );
1 Like

I get the following error:

  [...]\ClassB.cpp:7: erreur : C2248: 'UClassA::UClassA' : cannot access private member declared in class 'UClassA'
  [...]\ClassA.h:12: see declaration of 'AClassA::AClassA'
  [...]\ClassA.h:9: see declaration of 'AClassA'

when I create a subsubclass.

The problem occurs with the following code:

ClassA.h

#pragma once

#include "GameFramework/Actor.h"
#include "ClassA.generated.h"

UCLASS()
class PROBUILDER_API AClassA : public AActor
{
    GENERATED_BODY()
    AClassA( const FObjectInitializer& ObjectInitializer );

};

ClassA.cpp

#include "ProBuilder.h"
#include "ClassA.h"

AClassA::AClassA(const FObjectInitializer &ObjectInitializer):Super(ObjectInitializer)
{

}

ClassB.h

#pragma once

#include "ClassA.h"
#include "ClassB.generated.h"

UCLASS()
class PROBUILDER_API AClassB : public AClassA
{
    GENERATED_BODY()
    AClassB( const FObjectInitializer& ObjectInitializer );

};

ClassB.cpp

#include "ProBuilder.h"
#include "ClassB.h"


AClassB::AClassB(const FObjectInitializer &ObjectInitializer):Super(ObjectInitializer)
{

}

(I tried with a subclass of AActor and UMeshComponent and got the same errors)

1 Like

Here is the question on gamedev.stackexchange.

1 Like