Hello ! I'm trying to make an AssetLoader in my game and I'm having issues with the whole 'anonymous unions / structs'.
What I would like is to be able to access the textures from wherever I want in the code using AssetLoader::TEXTURE_NAME.
However, I would like to be able to access my textures not only with this TEXTURE_NAME but also with a table with indexes (so AssetLoader::TEXTURE_NAME for instance would also be AssetLoader::table[0]).
The code down below feels like it should work and I don't understand why it doesn't. The error is :
error: member 'sf::Texture AssetLoader::<unnamed union>::<unnamed struct>::ACE' with constructor not allowed in anonymous aggregate
AssetLoader.h ```Cpp
#pragma once
#include <SFML/Graphics/Texture.hpp>
struct AssetLoader final
{
inline static union {
sf::Texture table[4] {};
struct { sf::Texture ACE;
sf::Texture KING;
sf::Texture QUEEN;
sf::Texture JACK; };
} CARDS;
inline static sf::Texture BACKGROUND;
};
`main.cpp` ```Cpp
#include "AssetLoader.h"
int main()
{
if ( AssetLoader::CARDS.ACE.loadFromFile( "../assets/cards/ace.png" ) == false ) throw;
if ( AssetLoader::CARDS.KING.loadFromFile( "../assets/cards/king.png" ) == false ) throw;
if ( AssetLoader::CARDS.QUEEN.loadFromFile( "../assets/cards/queen.png" ) == false ) throw;
if ( AssetLoader::CARDS.JACK.loadFromFile( "../assets/cards/jack.png" ) == false ) throw;
return 0;
}
Does anyone have an idea of how to do what I'm trying to do ?
