I’m learning c++ and doing the tutorial at http://www.learncpp.com/
But as I’m going along I cant seem to figure out what :: and : mean. (I see them used all over in the code and google comes up short).
I’m learning c++ and doing the tutorial at http://www.learncpp.com/
But as I’m going along I cant seem to figure out what :: and : mean. (I see them used all over in the code and google comes up short).
:: (double colon) is the scope resolution operator. For example, when you see std::string, std is a namepsace and string is a symbol in the namespace std.
: (Single colon) is used in two places. The comparison operator (?and following access control keywords (public, protected and private) in class/struct declarations.
I’m terribly sorry for bringing this thread back from the dead, but there’s another use case for single colon that jCoder didn’t address. In the header files, you can often see stuff like this:
UPROPERTY(BlueprintReadWrite, Category=Actor)
uint32 bAutoDestroyWhenFinished:1;
I still haven’t figured out what that :1 at the end of the variable name means. Can anyone elaborate on this?
Thanks a lot in advance!
Not sure how its called, but you use it to specify how many bits you’re actually using allowing the compiler to optimize memory usage by packing variables together. In this case you’re telling the compiler you’re using only 1 bit. If you declare 8 variables like that, without other typed variables inbetween, then those 8 variables together only take up 8 bits instead of 8 * 32 bits.
I don’t know the proper name, but I’ve always called this a bit field operator. It allows you to define the number of bits that the variable will occupy. So above, even though a uint32 is defined as a 32-bit unsigned integer, it will only utilize 1 bit of that instead of 32.
You see this type of programming a lot in embedded systems where you often need to pad structs to occupy an exact number of bits. The above example is essentially turning a uint32 into a boolean. I’m not sure what the advantage is without seeing the context, maybe it was easier to set boolean values based on some number calculations… or maybe the original author is following their own style.
Aha yeah, that makes sense. I think that clears that up. Thanks a lot for the speedy replies, you two
EDIT: And for reference, that code was just an example I had handy, from AActor, I believe.
it’s called Bbtfields