user12580792
user12580792

Reputation:

What does the strange syntax mean in c++

In Unreal Project I have this line:

class USpringArmComponent* CameraBoom

and

class UCameraComponent* FollowCamera

And I haven't ever seen this syntax in c++. What does it mean?

Upvotes: 3

Views: 283

Answers (2)

Mary Chang
Mary Chang

Reputation: 955

That's just telling the compiler that UCameraComponent is a class. Not anything else. It's like in C you put struct before any structure variable declarations.

This syntax is useful when you have some messy code (or to convey that it is a class verbosely to the developer).

For example:

class counter
{
// bla bla bla...
};

void foo()
{
    int counter = 0; // Oops someone declared a variable called counter.
                     // How am I going to declare a variable of type `counter`?4
    // counter actual_counter; // Syntax error: expected ';' after expression.
                               //Because counter is a variable
    class counter actual_counter; // You prepend `class` to the deceleration
}

Upvotes: 3

Bathsheba
Bathsheba

Reputation: 234705

It's an elaborated type specifier:

https://en.cppreference.com/w/cpp/language/elaborated_type_specifier

Upvotes: 6

Related Questions