小编Jon*_*ely的帖子

进入main()之前的堆栈溢出异常

当用vs2010编译(和执行)这个c ++代码时,我甚至在它甚至可以向控制台一瞥"Start"之前就得到了一个堆栈溢出异常.

所有我使用的标题,文件都包含在stdafx.h中,但(包括标题,文件直接当同样的问题),这里显然不是问题.

堆栈跟踪如下:

>   msvcr100d.dll!__set_flsgetvalue()  Zeile 145 + 0xc Bytes    C
    msvcr100d.dll!_getptd_noexit()  Zeile 500   C
    msvcr100d.dll!_getptd()  Zeile 523 + 0x5 Bytes  C
    msvcr100d.dll!_LocaleUpdate::_LocaleUpdate(localeinfo_struct * plocinfo)  Zeile 243 + 0x5 Bytes C++
    003efe3c()  
    TerrainGenerator.exe!pre_cpp_init()  Zeile 298 + 0x21 Bytes C
Run Code Online (Sandbox Code Playgroud)

任何帮助都将非常感激,我是c ++的绝对初学者,正如你可能在代码风格中看到的那样,我尝试了一切以摆脱这个恼人的问题,例如甚至没有声明一个额外的功能等等. ..请帮助我,不要犹豫,询问您是否需要其他信息.提前致谢.

#include "stdafx.h"

int main(int argc, char* argv[])
{
    puts("Start");

    const int res = 4096;
    srand(time(NULL));

    uint16_t data[(res+1)*(res+1)];

    uint16_t variance = 2000;
    int seed = 1337;

    data[0] = ((seed>>1)+(int)(rand()/(RAND_MAX*(seed+(seed>>1)))));
    data[res] = ((seed>>1)+(int)(rand()/(RAND_MAX*(seed+(seed>>1)))));
    data[res*res] = ((seed>>1)+(int)(rand()/(RAND_MAX*(seed+(seed>>1)))));
    data[res*(res+1)] = ((seed>>1)+(int)(rand()/(RAND_MAX*(seed+(seed>>1))))); …
Run Code Online (Sandbox Code Playgroud)

c++ stack-overflow exception

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

如何使用cc在Solaris中编译c ++?

我写了一个程序,需要在Linux,WindowsSolaris上进行测试.前两个很容易,但Solaris非常麻烦.我在Solaris机器上没有g ++我正在运行那些测试,所以我坚持不懈cc.所以,我第一次尝试:

cc -g -o transfer transfer.cpp -lcurl
Run Code Online (Sandbox Code Playgroud)

输出是:

ld: fatal: file transfer.cpp : unknown file type
ld: fatal: no output written to transfer
Run Code Online (Sandbox Code Playgroud)

如果有人知道任何其他原生C++编译器Solaris,请告诉我,我会试一试.我去了Oracle Solaris网站,他们说他们支持.cpp文件cc.有人可以帮帮我吗?谢谢

c++ solaris

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

使用索引向量来擦除另一个向量的索引

我有两个向量,一个是我想要擦除的另一个向量的索引向量.目前我正在做以下事情:

#include <vector>
#include <iostream>
#include <string>

int main() {
        std::vector<std::string> my_vec;
        my_vec.push_back("one");
        my_vec.push_back("two");
        my_vec.push_back("three");
        my_vec.push_back("four");
        my_vec.push_back("five");
        my_vec.push_back("six");

        std::vector<int> remove_these;
        remove_these.push_back(0);
        remove_these.push_back(3);

        // remove the 1st and 4th elements
        my_vec.erase(my_vec.begin() + remove_these[1]);
        my_vec.erase(my_vec.begin() + remove_these[0]);

        my_vec.erase(remove_these.begin(), remove_these.end());

        for (std::vector<std::string>::iterator it = my_vec.begin(); it != my_vec.end(); ++it)
                std::cout << *it << std::endl;

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

但我认为这是不优雅和低效的.此外,我认为我必须小心对remove_these矢量进行排序并从最后开始(这就是我在索引0之前擦除索引3的原因).我想有一个擦除命令,类似于

my_vec.erase(remove_these.begin(), remove_these.end());
Run Code Online (Sandbox Code Playgroud)

但当然这不会起作用,因为my_vec.erase()期望迭代器引用相同的向量.

c++ vector

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

_GLIBCXX_USE_CXX11_ABI 在 RHEL6 和 RHEL7 上禁用?

我在 RHEL6 和 RHEL7 上安装了 gcc 5.2.1,看起来 _GLIBCXX_USE_CXX11_ABI 被禁用了。即使我手动运行它也不起作用-D_GLIBCXX_USE_CXX11_ABI=1 -std=c++14。这意味着我不会获得小字符串优化功能。例如,以下代码的输出始终为 8 和“micro not set”。对于 SSO,如果我们查看代码 bits/basic_string.h,std::string 的大小应至少为 16。有什么解决办法吗?

#include <string>
#include <iostream>

int main()
{
    std::cout << sizeof(std::string) << std::endl;

#if _GLIBCXX_USE_CXX11_ABI
    std::cout << "macro set" << std::endl;
#else
    std::cout << "macro not set" << std::endl;
#endif

}
Run Code Online (Sandbox Code Playgroud)

c++ libstdc++ devtoolset rhel6 rhel7

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

shared_ptr初始化

成员定义为

std::shared_ptr<std::array<std::string, 6> > exit_to;
Run Code Online (Sandbox Code Playgroud)

这表示其他人共享的其他数据.当尝试启动指针"exit_to"时.正确的方法是

node_knot.exit_to = std::make_shared<std::array<std::string, 6> >();
Run Code Online (Sandbox Code Playgroud)

但它在另一个文件中,我想保持指针类型一致,如下所示:

node_knot.exit_to = std::make_shared<decltype(*node_knot.exit_to)>();
Run Code Online (Sandbox Code Playgroud)

但是不会编译:

 /usr/include/c++/4.6/bits/shared_ptr_base.h:798:54: error: '__p'
 declared as a pointer to a reference of type
 'std::array<std::basic_string<char>, 6> &'
         __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
                                                             ^ /usr/include/c++/4.6/bits/shared_ptr.h:93:31: note: in instantiation
 of template class
 'std::__shared_ptr<std::array<std::basic_string<char>, 6> &, 1>'
 requested here
     class shared_ptr : public __shared_ptr<_Tp>
                               ^ ../node_booker.h:757:20: note: in
 instantiation of template class
 'std::shared_ptr<std::array<std::basic_string<char>, 6> &>' requested
 here
                                                         n.exit_to = std::make_shared<decltype(*n.exit_to)>();
Run Code Online (Sandbox Code Playgroud)

我在Ubuntu 12.10下,clang ++ 3.2,--std = c ++ 11

c++ shared-ptr decltype

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

mingw std::thread 与 Windows API

std::thread到目前为止,我开始使用 C++11 (mingw 4.8)很好。我遇到了 I/O 重叠的情况,sleepEx用于将线程置于可警告的等待状态。这工作得很好,直到QueueUserAPC必须使用,返回“无效句柄错误”。

经过一番搜索发现,std::thread在Windows下使用了pthread库。

有什么方法可以使用 Windows API 调用,它需要一个线程句柄std::thread吗?或者我是否需要坚持使用 Windows 线程来实现重叠 I/O?

windows mingw c++11 stdthread

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

为什么在创建类对象数组时无法调用参数化构造函数?

我是C++的新手,我需要对构造函数做一些澄清,我的问题是:

  1. 我们可以在创建类对象数组时使用参数化构造函数吗?
  2. 或者,在创建类对象数组时是否只能使用默认构造函数?

请解释如何完成,或为什么不能.我需要对此有更深入的了解.

c++ default-constructor construct

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

MacOSX共享库:体系结构x86_64的未定义符号

我在使用MacOSX上的共享库编译代码时遇到了一些麻烦.在尝试在MacOSX上编译之前,我首先在Debian上编写了它.

这是代码:

test.hxx:

#ifndef TEST_HXX
#define TEST_HXX

namespace test
{
    class CFoo
    {
        /* data */
    public:
        CFoo (){}
        virtual ~CFoo (){}
        void bar();

    }; /* CFoo */
} /* namespace test */

#endif /* TEST_HXX */
Run Code Online (Sandbox Code Playgroud)

test.cxx:

#include <iostream>

#include "test.hxx"

void test::CFoo::bar()
{
    std::cout << "Hello world!" << std::endl;
} /* bar() */
Run Code Online (Sandbox Code Playgroud)

other.hxx:

#ifndef OTHER_HXX
#define OTHER_HXX

namespace other
{
    class CBar
    {
    public:
        CBar (){}
        virtual ~CBar (){}
        void foo();

    }; /* CBar */
} /* …
Run Code Online (Sandbox Code Playgroud)

c++ macos makefile shared-libraries clang++

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

C++程序中非常奇怪的堆栈溢出

我不久前写了一个程序(Mac OS X,C++,SDL,FMOD),它表现得相当不错.但最近我想扩展其功能并为其添加更多代码.现在,当我运行它并尝试测试新功能时,程序会与SIGABRT崩溃.

查看调试器,在函数堆栈上我看到:

  • _杀
  • 杀$ UNIX2003
  • 提高
  • __abort
  • __stack_chk_fail
  • odtworz < - 我的功能被修改了

据我所知,"__ stack_chk_fail"表示堆栈溢出.但这不是最奇怪的事情.在这个函数"odtworz"中,我有一些像这样的代码:

...

koniec = 0;
while ( koniec == 0 ) {
    ...
    if (mode == 1) {
        ...
    }
    else if (mode == 2) {
        ...
    }
    else if (mode == 3) {
       piesniOrkiestrowe[0] = '\0'; 
       while ( piesniOrkiestrowe[0] == '\0' ) { 
           losowaPiesn(); 
           char * piesnOrkiestrowa = szukajPiesniOrkiestrowej(); 
           if ( piesnOrkiestrowa != NULL ) 
              strcpy(piesniOrkiestrowe, piesnOrkiestrowa); 
       } 
       char nowyPiesnPlik[25]; 
       sprintf(nowyPiesnPlik, "%sorch/%s", PIESNI_DIR.c_str(), piesniOrkiestrowe); …
Run Code Online (Sandbox Code Playgroud)

c++ stack-overflow macos callstack

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

静态库中带有extern模板的未定义符号

据我所知,新的extern模板功能可以加快编译和链接时间.我试图在一个(静态)库中使用它,据我所知,它应该可以工作,因为Bjarne Stroustrup的C++ 11 FAQ明确提到了库.

我所拥有的是包含某些内容的头文件

template <typename T>
class Foo {
  // Definitions of the methods
};

extern template class Foo<int>;
Run Code Online (Sandbox Code Playgroud)

和一个实现文件

#include "Foo.hpp"
template class Foo<int>;
Run Code Online (Sandbox Code Playgroud)

这些用于构建静态库libfoo,然后链接到相应的单元测试FooTest.然后,链接为我在测试中调用Foo对象的每个方法提供了未定义的符号错误.

我在做什么/出错了?

c++ templates extern c++14

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