【发布时间】:2019-05-09 17:56:50
【问题描述】:
我正在使用来自另一个库的类 (sf::Texture)。
我想获得在该类中声明类型别名的功能,例如:
class Texture
{
public:
using ResourceId = TextureId;
//...
}
这样我就可以在我的代码中做到这一点:
enum class TextureId
{
texture1,
texture2 //..etc
}
template<class ResourceType>
class ResourceContainer
{
public:
ResourceContainer();
private:
ResourceType* resource_;
typename ResourceType::ResourceId id; // <--- this will have TextureId type
// when we create this object
// with <sf::Texture>
}
但是,正如我所提到的,Texture 类来自另一个库,因此我无法编辑它的声明。
我试图在我的代码中将其声明为using sf::Texture::ResourceId = TextureId;,但它不起作用(无法解析符号ResourceId)。
那么,有没有其他方法可以在不添加ResourceId 作为第二个模板参数的情况下获得相同的功能?
(使用 C++17)
【问题讨论】: