我正在尝试定义基类,它只包含typedef.
template<typename T>
class A
{
public:
typedef std::vector<T> Vec_t;
};
template<typename T>
class B : public A<T>
{
private:
Vec_t v; // fails - Vec_t is not recognized
};
Run Code Online (Sandbox Code Playgroud)
BI中为什么会收到Vec_t无法识别的错误,我需要明确写出来?
typename A<T>::Vec_t v;
Run Code Online (Sandbox Code Playgroud) 今天我对这段代码片段的名称引用不明确这一事实感到震惊:
class A
{
private:
typedef int Type;
};
class B
{
public:
typedef int Type;
};
class D : A, B
{
Type value;//error: reference to 'Type' is ambiguous
};
Run Code Online (Sandbox Code Playgroud)
唔!假设您是 class 的作者,A并且您的 class 已经被不同的人和不同的项目随处使用。有一天你决定重写你的A类。这是否意味着您不能在不破坏他人代码的情况下在新类中使用任何新的(甚至私有的)名称?
这里的约定是什么?