How can i use in A class value, to B class in C++

A.h

class A
{
    public:
    A();
    float Aspeed;
}

A.cpp

A::A()
{
    Aspeed = 10.f;   
}

/-------------------------------------------------/

B.h

class B
{
    public:
    b();
    float Bspeed;       
}

B.cpp

B::B()
{
    Bspeed =    [ i want to get Aspeed of class A      ]   <- What do i write ????
}

i want connect two different class.

i can’t see example.

could you make simple easy example ?? please…

There are multiple possible solutions. What do you want to achieve? Then i can give you a better tip.

dear fabianu

hmmm…

i want to get member value of other class.

That class is not parent and child.

i need general example…

connect different other class!!

i’m sorry… my question range is so large TT_TT

for example

in class A

UStaticMeshComponent* AAA = CreateDefaulSubobject


in class B

I want use value of AAA!!

How to connect???

You need to instantiate class A within class B then access the variable you declared. Bspeed = A.Aspeed;

This is a basic function of any programming language, and not to be discouraging but you won’t be able to do much in C++ without that basic knowledge. Try sticking to blueprints, which for you should not have any disadvantages compared to trying to do it in C++. There are many UE4 tutorials on YouTube.

This should work:

TSubclassOf<A> asd = A::StaticClass();
Bspeed = asd.GetDefaultObject()->Aspeed;

Hey psr1331-

Inside the .h for class be you will first need to add an include statement for Class A. Once you’ve done this you can create a variable inside Class B who’s type is of Class A (which would look like A MyClassARef). From this variable, as HuntaKiller mentioned, you can then get the specific atribute of class A that you need. In the case of your example it would be BSpeed = MyClassARef.ASpeed. For this to work, ASpeed needs to be declared public inside Class A so that another class can see/use it.

Cheers