我听说volatile是像const这样的重载因素.
如果一个函数被volatile参数重载,那么什么时候调用volatile-version?
我无法想象调用volatile-version时的情况.
啊
template <typename T>
class A
{
public:
int a;
}
Run Code Online (Sandbox Code Playgroud)
BH
template <typename T>
class B : public A<T>
{
public:
int f();
}
template <typename T>
int B<T>::f()
{
int t;
t = this->a; //Okay
t = a //Error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么我不使用时会发生错误this->?
我可以省略this->使用某种方法吗?
(我修正了一些错误)
可能重复:
如何在C++中使用基类的构造函数和赋值运算符?
class A
{
protected:
void f();
}
class B : public A
{
protected:
void f()
{
A::f();
}
}
Run Code Online (Sandbox Code Playgroud)
我们可以用这种方式使用父类的功能,但我不知道如何使用父类的运算符.
让我们A重载类operator=
如果我A按值调用一个具有参数的函数,那么重载operator=是否会被调用?
例如,我想看pA
int *pA = new int[LEN];
Run Code Online (Sandbox Code Playgroud)
然后在visual studio中,我只能在观察窗口看到pA [0]
我尝试查看'(int(*)[LEN])pA',但它不起作用
我不想做
int (*test)[LEN] = (int (*)[LEN])pA
Run Code Online (Sandbox Code Playgroud)
调试
如何在VS2010的调试器中将动态分配的指针看作静态数组?
template <typename T>
class A
{
public:
A() {p = this;}
static A *GetP() {return p;}
private:
static A *p;
static A instance;
}
template <typename T>
A<T> *A<T>::p = (A<T> *)4534; //just test value to check whether p is initiallized or not.
template <typename T>
A<T> A<T>::instance;
Run Code Online (Sandbox Code Playgroud)
我打电话A<int>::GetP().我希望它返回实例的地址,但它返回(A<int> *)4534.另外,没有调用构造函数.
我认为这意味着p初始化很好,但实例不是.
但是,如果我特意把它像这样,
A<int> A<int>::instance
Run Code Online (Sandbox Code Playgroud)
它运作良好.为什么会出现这种现象?
c++ ×6
inheritance ×2
overloading ×2
templates ×2
debugging ×1
function ×1
operators ×1
volatile ×1