小编Ric*_*ick的帖子

c ++错误:数组下标的类型'int [int]'无效

尝试学习C++并在数组上进行简单的练习.

基本上,我已经创建了一个多维数组,我想创建一个打印出值的函数.

Main()中的注释for循环工作正常,但是当我尝试将for循环转换为函数时,它不起作用,对于我的生活,我看不出原因.

#include <iostream>
using namespace std;


void printArray(int theArray[], int numberOfRows, int numberOfColumns);

int main()
{

    int sally[2][3] = {{2,3,4},{8,9,10}};

    printArray(sally,2,3);

//    for(int rows = 0; rows < 2; rows++){
//        for(int columns = 0; columns < 3; columns++){
//            cout << sally[rows][columns] << " ";
//        }
//        cout << endl;
//    }

}

void printArray(int theArray[], int numberOfRows, int numberOfColumns){
    for(int x = 0; x < numberOfRows; x++){
        for(int y = 0; y < numberOfColumns; y++){ …
Run Code Online (Sandbox Code Playgroud)

c++

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

子类如何使用子类的相同方法名称调用超类的方法?

#include <iostream>
using namespace std;

class Person {
public:
    void sing();
};

class Child : public Person {
public:
    void sing();
};

Person::sing() {
    cout << "Raindrops keep falling on my head..." << endl;
}

Child::sing() {
    cout << "London bridge is falling down..." << endl;
}

int main() {
    Child suzie;
    suzie.sing(); // I want to know how I can call the Person's method of sing here!

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
1万
查看次数

继承子类时的默认保护级别是什么?

可能重复:
默认类继承访问

我知道我可以在从超类声明子类时设置保护级别,如下所示:

class Dog : public Pet {
   *blah, blah, blah*
}
Run Code Online (Sandbox Code Playgroud)

但是在这种情况下保护级别默认为什么?

Class Dog: Pet {
   *blah, blah, blah*
}
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

0
推荐指数
1
解决办法
232
查看次数

标签 统计

c++ ×3

inheritance ×1