相关疑难解决方法(0)

为什么#include <string>会阻止堆栈溢出错误?

这是我的示例代码:

#include <iostream>
#include <string>
using namespace std;

class MyClass
{
    string figName;
public:
    MyClass(const string& s)
    {
        figName = s;
    }

    const string& getName() const
    {
        return figName;
    }
};

ostream& operator<<(ostream& ausgabe, const MyClass& f)
{
    ausgabe << f.getName();
    return ausgabe;
}

int main()
{
    MyClass f1("Hello");
    cout << f1;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我注释掉,#include <string>我没有得到任何编译器错误,我想因为它包含在内#include <iostream>.如果我在Microsoft VS中"右键单击 - >转到定义",它们都指向xstring文件中的同一行:

typedef basic_string<char, char_traits<char>, allocator<char> >
    string;
Run Code Online (Sandbox Code Playgroud)

但是当我运行我的程序时,我收到一个异常错误:

OperatorString.exe中的0x77846B6E(ntdll.dll):0xC00000FD:堆栈溢出(参数:0x00000001,0x01202FC4)

知道为什么我在评论时出现运行时错误#include <string> …

c++ stack-overflow string explicit

121
推荐指数
2
解决办法
7251
查看次数

什么是聚合初始化

"Thinking in Java,2nd Edition"的第4章,第231页中的"数组初始化"部分有这样的说法:

在C中初始化数组容易出错且乏味.C++使用聚合初始化使其更安全.Java没有像C++这样的"聚合",因为Java中的所有东西都是对象.它有阵列,阵列初始化支持这些阵列.

为什么C中容易出错且乏味?聚合初始化是什么意思,为什么它更安全?我在Bruce Eckel的"Thinking in C++"(第2版)中遇到了"聚合初始化"这一章,但它并没有让我相信任何事情.

c++

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

标签 统计

c++ ×2

explicit ×1

stack-overflow ×1

string ×1