小编use*_*866的帖子

将整数添加到c中的char数组

这可能是一个愚蠢的问题,但仍然没有解决。我确实有一个char数组,说char arr [100]有一些数据

 char arry[100] ---- some data;
 int test;
 memcpy(&test,array+4,sizeof(int))
Run Code Online (Sandbox Code Playgroud)

此memcpy将做什么谢谢SKP

c

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

将Object初始化为另一个类的成员

我只是想了解它是如何发生的,因为它是c ++的新手.

让我详细说明我的问题陈述.

class test1 {
public:
    test1() {
        cout << " test1::constructor called" << endl;
    }
    ~test1() {
        cout << " test1::destrcutor called" << endl;
    }
};

class test2 {
public:
    test2() {
        cout << " test2::constructor called" << endl;
    }
    ~test2() {
        cout << " test2::destrcutor called" << endl;
    }
};

class derived :public test1, public test2 {
    test2 t2;
    test1 t1;
public:
    derived() {
        cout << " derived constructor called" << endl;
    }
    ~derived() {
        cout << …
Run Code Online (Sandbox Code Playgroud)

c++

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

类具有自定义对象

想了解为什么没有编译错误

如果一个类具有相同类型的静态对象,并且该类具有参数构造函数,为什么在创建它时却没有

class test {

      static test a;
      int b;

      public:
            test(int arg) {
                 b = arg;
              }
};

int main() {
  test t1(100);

  return 0;

}
Run Code Online (Sandbox Code Playgroud)

我知道要使其正常工作,我需要添加为

 test test::a(100)
Run Code Online (Sandbox Code Playgroud)

但是没有上面的行,为什么没有编译错误。任何指针

c++

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

标签 统计

c++ ×2

c ×1