I got a surprising result with const functions, and I could use some clarification if anyone knows the root of this:
While playing around I made a const member function that passes an output (WordListOut) by parameter:
void UBullCowCartridge::GetValidWordsFromList(const TArray& WordListIn, TArray& WordListOut, int32 MaxWordLength) const
Inside of this function, after pairing down the list of passable words and storing them in a temp TArray called TempWordList, I assign the output parameter WordListOut to the temp array to return it (via reference):
WordListOut = TempWordList;
I also have a member variable:
TArray ValidHiddenWordList = { TEXT(“default”) };
Now, the interesting thing is if I pass this member variable ValidHiddenWordList into the GetValidWordsFromList() function as the output parameter:
GetValidWordsFromList(SomeList, ValidHiddenWordList, SomeInt);
The program will then compile and run without issue, even though I am breaking the const attribute of my member function GetValidWordsFromList() by directly assigning a new value to my member variable ValidHiddenWordList (albeit though an alias).
Is it expected that the compiler doesn’t catch this loophole (I am using VS Community 19)? Is it only smart enough to catch blatant fouls (i.e. ValidHiddenWordList = SomeOtherList) and this is a known limitation?
Thanks in advance for your thoughts.