小编use*_*252的帖子

C++初始化类的成员数组的所有值

在C++中如何初始化类的成员数组的所有值?

#define MAX_MATRIX 20
Class Matrix {
public:   
         Matrix(); //constructor
protected:
         int n[MAX_MATRIX];   // note cannot do = { 0} or w/e here
};

Matrix::Matrix()
{
     // how to set all n to -1?
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays initialization class

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

在你返回false之后你需要休息吗?

在bool函数内的switch语句中,我有这个.我是否添加了休息或暗示我在这方面非常糟糕.

case Stop:
default:
    return false;
//break;??????
Run Code Online (Sandbox Code Playgroud)

c++ return break switch-statement

3
推荐指数
2
解决办法
5898
查看次数

如何在linux上编译C++来制作Windows二进制文件

可能重复:
如何使用gcc/g ++在Linux上编译Windows?

我们这里没有windows如何为某些ppl编译这个程序?是否有一些Wine for Linux程序可以在Windows上运行或什么.

c++ windows binary compilation

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

从一个短整数中拼出第一个和最后一个3位数?

我在这个数组中有很多变量:short num = 7123;.该值总是4位数.怎么去把它变成 a = 7; b = 123;

我能想到的只是转换为c-string并将其剥离,但似乎效率不高.

c++ integer short splice

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

试图重载cout <<运算符,但它不起作用

我在这里剪掉了我班上不相关的部分.我不知道我做错了什么,只是想尝试能够cout <<对象.

#include <iostream>

class Snipped
{

    public:
        friend std::ostream& operator<<(std::ostream& os, const Snipped& s);

    protected:
    private:
};

std::ostream& operator<<(std::ostream& os, const Snipped& s)
{
    os << "test";
    return os;
}

int main(int argc, char* argv[])
{
    Snipped* s = new Snipped();

        std::cout << s << std::endl << s;

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

预期产量:

test
test
Run Code Online (Sandbox Code Playgroud)

实际产量:

0x12ae20
0x12ae20  (random memory location?)
Run Code Online (Sandbox Code Playgroud)

c++ overloading operator-keyword

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

在堆栈或堆上创建的类成员?

需要知道是否会在堆栈中或堆上创建这样的3d矩阵,如果它在堆栈上如何新建它并正确初始化默认值(memset)

class Matrix {
     protected:
         int n[9000][420]; // is stack or heap if VVV is pointer?
};

void main()
{
         Matrix* t = new Matrix(); // created on heap
}
Run Code Online (Sandbox Code Playgroud)

c++ heap stack class

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