-4

プログラムは、シグナル SIGFPE、算術例外を受け取りました。xxx::init (this=0xbffe47fc, aa=0x0) at s.cc:1061 1061 価格 = 100.0;

別の Linux マシン RH5.6 32 ビットでコードを変更せずにコンパイルして実行しようとしましたが、このアプリケーションの所有者は RH5.3 で問題なくコンパイルしました。

gdb bt

B::初期化

b_init

B::B

あ::あ

主要

ここにコードがあります

class A : public B
{
A () : a_1(1)
{
    init()
}

void init();

int a_1;
};

class B
{
double price;

B() 
{
memset(this, 0, sizeof(*this);
b_init(this);
}

int b_init( B* b)
{
return b->init();
}

void init()
{
price = 100.0;
}
};

int main()
{
A a;
}

私にはとても普通に見えます。誰かがそれにいくつかの光を当てることができますか? ありがとう!

4

1 に答える 1

0

このテストコードは私にとってはうまくいきます。他に何かあるに違いない?

#include <iostream>
using namespace std;

struct teststruct
{
  int a;
  double b;
};

class test_class
{
public:
  void init( struct teststruct * );
  double getPrice();
private:
  double price;
};

void test_class::init( struct teststruct *test )
{
  price = 100.0;
}

double test_class::getPrice()
{
  return price;
}

int main ()
{
  struct teststruct a;
  test_class test;

  test.init(&a);
  cout << "Double " << test.getPrice() << endl;

  return 0;
}

出力:

[hendric@Linux-Test-System ~]$ g++ doubletest.cpp 
[hendric@Linux-Test-System ~]$ ./a.out
Double 100
于 2014-02-28T02:25:50.553 に答える