Announcement

Collapse
No announcement yet.

cant create array of pointers

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

    cant create array of pointers

    Code:
    MyStruct Var1;
    MyStruct Var2;
    MyStruct Var3;
    TArray<MyStruct*> MyArray;
    Code:
    void MyClass::AddPointerToArray()
    {
        MyArray.Add(&Var1);
        MyArray.Add(&Var2);  
        MyArray.Add(&Var3);  
    };
    ***.h(394) : Error: Inappropriate '*' on variable of type 'MyStruct', cannot have an exposed pointer to this type.

    #2
    same with
    Code:
    MyStruct* MyArray[] = {&Var1, &Var2, &Var3};
    Last edited by Repin Design; 11-13-2017, 07:09 AM.

    Comment


      #3
      Would need to see the definition of "MyStruct" to be sure, but is your data a UClass or UStruct as base? (I'm thinking UStruct.) If so, better off passing by value rather than pointers (more here: https://answers.unrealengine.com/que...uproperty.html)







      Comment


        #4
        If you want to pass your custom struct as a reference instead of only copy value, inside your struct you must declare a proper GetHashType(const MyStruct&) and declare all the boolean operators needed for type miss/matching as well.

        Then you can do FMyStruct* myStruct;

        Also, you can't use TArray with native types. It should be a UStruct; UStructs always begin with a 'F' prefix.
        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

        Comment


          #5
          You can use a TArray with native types if you wrap those into a smart pointer aka TSharedPtr
          Sr. Engine Programmer @ www.playspace.com - moritzwundke.com
          Remember: be polite and respect other peoples opinions - Join the Unofficial Unreal Discord Channel - Found a bug? Then use the Bug Report Form to get it fixed ^^

          Comment


            #6
            Yes, but I guess his TArray is UProperty() too. In this case it simply can't be a pointer because UBT will throw exception if he use struct pointer as UProperty.
            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

            Comment


              #7
              Yep no prop for non-UE types, to fix that I just create an UObject/UStruct wrapper and serialize what I need ^^. That would also work for his case.
              Sr. Engine Programmer @ www.playspace.com - moritzwundke.com
              Remember: be polite and respect other peoples opinions - Join the Unofficial Unreal Discord Channel - Found a bug? Then use the Bug Report Form to get it fixed ^^

              Comment


                #8
                Originally posted by BrUnO XaVIeR View Post
                If you want to pass your custom struct as a reference instead of only copy value, inside your struct you must declare a proper GetHashType(const MyStruct&) and declare all the boolean operators needed for type miss/matching as well.

                Then you can do FMyStruct* myStruct;

                Also, you can't use TArray with native types. It should be a UStruct; UStructs always begin with a 'F' prefix.
                Originally posted by BrUnO XaVIeR View Post
                Yes, but I guess his TArray is UProperty() too. In this case it simply can't be a pointer because UBT will throw exception if he use struct pointer as UProperty.
                Thanks alot.

                Comment

                Working...
                X