小编Hel*_*ter的帖子

关于双指针和三指针/双维数组

所以,我正在玩C指针和指针算术,因为我对它们不太满意.我想出了这段代码.

char* a[5] = { "Hi", "My", "Name", "Is" , "Dennis"};
char** aPtr = a; // This is acceptable because 'a' is double pointer
char*** aPtr2 = &aPtr; // This is also acceptable because they are triple pointers
//char ***aPtr2 = &a // This is not acceptable according to gcc 4.8.3, why ?

//This is the rest of the code, the side notes are only for checking
printf("%s\n",a[0]); //Prints Hi
printf("%s\n",a[1]); //Prints My
printf("%s\n",a[2]); //Prints Name
printf("%s\n",a[3]); //Prints Is
printf("%s\n",a[4]); …
Run Code Online (Sandbox Code Playgroud)

c pointers pointer-to-pointer

5
推荐指数
1
解决办法
142
查看次数

与C++中的虚拟关键字混淆

我正在研究virtual关键字在C++中的效果,我想出了这段代码.

#include<iostream>

using namespace std;

class A {
public:
    virtual void show(){
        cout << "A \n";
    }
};

class B : public A {
public:
    void show(){
        cout << "B \n";
    }
};

class C : public B {
public: 
    void show(){
        cout << "C \n"; 
    }
};

int main(){

    A *ab = new B;
    A *ac = new C;
    B *bc = new C;
    ab->show();
    ac->show();
    bc->show();

}
Run Code Online (Sandbox Code Playgroud)

预期的产出是:

B
C
B
Run Code Online (Sandbox Code Playgroud)

因为showB中的函数是非虚拟的.但是编译它的结果是:

B
C …
Run Code Online (Sandbox Code Playgroud)

c++ virtual inheritance function c++11

5
推荐指数
2
解决办法
546
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

function ×1

inheritance ×1

pointer-to-pointer ×1

pointers ×1

virtual ×1