I've been trying to create a header file that will declare a TArray of FStrings but keep getting the following compiler error:
"C++ no instance of constructor matches the argument list argument types are: (const wchar_t [6], const wchar_t [6], const wchar_t [6], const wchar_t [6], const wchar_t [6])"
I have read the documentation from Unreal here on declaring and initializing a TArray to no avail: https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/TArrays/index.html
const TArray<FString> WordList;
WordList.Add("test");
When attempting this, the compiler throws an error stating that there is no storage class or type specifier.
What is the correct way of declaring a TArray within a header file in Unreal?
#include "CoreMinimal.h"
const TArray<FString> WordList = {
TEXT("chart"),
TEXT("quest"),
TEXT("crows"),
TEXT("bears"),
TEXT("loves") };
It seems ok, and it compiles in my VStudio, I am not sure about that error, but to be exact the error says that you created a TArray of "FString" items and you are adding TEXT("abcd") which is of type "wchar_t*". Try this one:
#include "CoreMinimal.h"
const TArray<wchar_t*> WordList = {
TEXT("chart"),
TEXT("quest"),
TEXT("crows"),
TEXT("bears"),
TEXT("loves") };
or
#include "CoreMinimal.h"
const TArray<FString> WordList = {
"chart",
"quest",
"crows",
"bears",
"loves" };
The below code will work only in .cpp file and you should drop const
to work with Add
:
TArray<FString> WordList;
WordList.Add("test");