Announcement

Collapse
No announcement yet.

What Does The Star (*) After UTexture Mean?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    What Does The Star (*) After UTexture Mean?

    I know what it would mean before it, but what does it mean after?

    #2
    IIRC It means a Pointer to a Variable of type UTexture.

    I believe it creates a pointer to a variable of a specific type, but you can change what specific object it points to, AKA it doesn't have to be implemented straight away.

    I believe it reserves a specific amount of memory at a specific location so you can come back to it later and you can always reference it in your code, even if there's nothing technically "there". Don't quote me on this though, I'm by no means an expert.

    Comment


      #3
      Originally posted by TheJamsh View Post
      IIRC It means a Pointer to a Variable of type UTexture.

      I believe it creates a pointer to a variable of a specific type, but you can change what specific object it points to, AKA it doesn't have to be implemented straight away.

      I believe it reserves a specific amount of memory at a specific location so you can come back to it later and you can always reference it in your code, even if there's nothing technically "there". Don't quote me on this though, I'm by no means an expert.
      Sounds good to me -- thanks! The funny thing is, I searched high and low on Google for the answer, but nothing about it. It must be such an easy concept no one even talks about it, lol.

      Comment


        #4
        I think most people usually put it before instead of after, though I'm not entirely sure it makes a difference. Once again though, I could be talking rubbish

        Comment


          #5
          http://www.cplusplus.com/files/tutorial.pdf

          Page 63

          The concept of pointers is *well* discussed

          Comment


            #6
            Consider lines:

            Code:
            UTexture* MyTexture; // defines a pointer to an object of type UTexture
            MyTexture = NewObject<UTexture>();// instantiates the object (allocates memory and calls the constructor)
            defines a variable called MyTexture that is a pointer to an object of type UTexture. A pointer is a variable that holds the ADDRESS of the object you are pointing to in memory. No memory is allocated for the object itself on the first line above.

            See standard C or C++ docs for more details on pointers.

            Comment


              #7
              That's the weirdest thing for me -- I get that it's a pointer, but why does it come after the variable in Unreal C++, but seemingly always before in regular C++ examples online?

              Comment


                #8
                You can write

                void* MyPointer;

                or void * MyPointer;

                or void *MyPointer;

                Thats all fine, but if you write it directly after the type name its more clear that you define a pointer to that type.

                But take care, if you create a list its better to put the star before the variable name, as

                int* pt1, pt2, pt3;

                ..creates one pointer and two normal variables.

                So you'd write

                int *pt1, *pt2, *pt3;
                Last edited by Mikand79; 10-24-2014, 11:11 AM.

                Comment


                  #9
                  Originally posted by AllenGingrich View Post
                  That's the weirdest thing for me -- I get that it's a pointer, but why does it come after the variable in Unreal C++, but seemingly always before in regular C++ examples online?
                  http://stackoverflow.com/questions/2...tween-the-type
                  http://stackoverflow.com/questions/3...after-the-type

                  Those might help explain it.
                  Last edited by InfectedFPS; 10-24-2014, 11:06 AM.
                  Twitter: @InfectedFPS
                  Twitch: InfectedFPS (Occasionally stream some work)

                  Comment


                    #10
                    Originally posted by AllenGingrich View Post
                    That's the weirdest thing for me -- I get that it's a pointer, but why does it come after the variable in Unreal C++, but seemingly always before in regular C++ examples online?
                    Make sure you don't confuse it with a dereferencing operator also, which looks like *VariableName.

                    Comment


                      #11
                      why does it come after the variable in Unreal C++, but seemingly always before in regular C++ examples online?
                      It doesn't come after the variable, it comes after the type.

                      Code:
                      struct Type {  // define a type
                        int foo;
                      };
                      
                      Type * variable = NULL;  // define a variable as pointer-to-type
                      
                      variable = new Type();  //  assign a value to a variable
                      
                      (*variable).foo = 2;    // dereference a pointer variable (style 1)
                      assert(variable->foo == 2);    //  dereference a pointer variable (style 2)
                      Style 1 and style 2 are equivalent unless very peculiar operator overloading is involved.

                      Comment


                        #12
                        As jwatte said, it comes after the type, not the variable(name/label).

                        One of the major reason for this is C++ likes to reuse the hell out of operators, with * tacking triple duty... declaration of a pointer, dereference a pointer and multiplication, so this totally valid (and ugly) C++ code for example:

                        Code:
                        int *i, *j, k = 42;
                        	i = j = &k;
                        	std::cout << *i * *j << std::endl;

                        Comment


                          #13
                          As jwatte said, it comes after the type, not the variable. The astericks operator pulls triple duty in C++, declaring a pointer, dereferencing a pointer and multiplication operation. Making the following horrid code valid:

                          Code:
                          	int *i, *j, k = 42;
                          	i = j = &k;
                          	std::cout << *i * *j << std::endl;

                          Comment


                            #14
                            http://www.cplusplus.com/doc/tutorial/pointers/
                            [On Hold]WIP: Vertex-Based Ledge Detection/Parkour Engine

                            Looking for fellow programmers to develop a project.

                            Comment

                            Working...
                            X