3

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?

5
  • 1
    What is strange for you, exactly? Did you know what pointers are, in C++? If not: consider learning from a good C++ book. Commented Aug 4, 2020 at 12:47
  • What part is strange to you? The pointers or the use of the word class? In either case I would suggest read more about C (read about structs instead of classes) because both these come from C. Commented Aug 4, 2020 at 12:50
  • 4
    This is a dark corner of the language - difficult to search for if you don't know the term. Downvotes are harsh IMHO. Commented Aug 4, 2020 at 12:51
  • I agree with @Bathsheba, this is a good question. Commented Aug 4, 2020 at 12:56
  • 1
    The * means the type is a pointer, and the pointer may point to a USpringArmComponent type (in the first case) for the variable CameraBoom, or to a UCameraComponent type (in the second case) for the variable FollowCamera. Commented Aug 4, 2020 at 12:58

2 Answers 2

6

It's an elaborated type specifier:

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for finding the verbiage! I didn't know what to call that syntax.
3

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 } 

3 Comments

I know. I though a beginner friendly approach would be better in this question.
Trivial edit to convert the downvote to an upvote. Sorry for trolling.
Interesting! I did not know that! Because I don't normally do that kind of thing. I was able to do it this way: class std::basic_string<char, std::char_traits<char>, std::allocator<char> > s; But it doesn't parse with the typedef class std::string s;.