小编sou*_*dar的帖子

引用派生类时基类的对象大小

#include<bits/stdc++.h>

using namespace std;

class abc {
  public:
    int a = 45;
  void sum() {
    int s = 55;
    cout << s + a << endl;
  }
};
class xyz: public abc {
  public: int b = 45;
  int c = 54;
  int d = 96;
  int x = 8;
  void show() {
    cout << "xyz class" << endl;
  }
};
int main() {
  abc * ob;
  xyz d;
  ob = & d;
  cout << sizeof( * ob) << endl; …
Run Code Online (Sandbox Code Playgroud)

c++ size sizeof c++11 c++14

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

为什么我们需要在 Java 中处理或抛出检查异常?

我是Java新手,我读到仅在编译时引发检查异常,即如果存在未处理或抛出的检查异常,程序将无法成功编译。如果有什么东西阻止编译器编译代码,那么我们可以删除它或以其他方式重新编码,这样问题就不会存在。

例如,如果我们试图打开系统中不存在的文件,我们不应该只是打开它。那么为什么需要处理/抛出这些异常呢?

java exception checked-exceptions

-1
推荐指数
1
解决办法
1209
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1

checked-exceptions ×1

exception ×1

java ×1

size ×1

sizeof ×1