0

これらは g++ が出力しているエラー/警告であり、それぞれの下に関連するコードがあります。これらのエラーを解決したり、それらに光を当てたりするための助けをいただければ幸いです。ありがとうございました!

g++ エラー:

id31.cpp: In function ‘php_var array(int, ...)’:
id31.cpp:462: warning: cannot receive objects of non-POD type ‘class php_var’ through ‘...’; call will abort at runtime
id31.cpp:480: warning: cannot receive objects of non-POD type ‘class php_var’ through ‘...’; call will abort at runtime

関連コード:

#include <stdarg.h>
php_var array(int key = 0, ...)
{
    va_list ap;
    va_start(ap, key);
    php_var arr;
    arr.to_array();
    int i = 0;
    for(int i = 0; i < key / 2; ++i)
    {
        php_var key2 = va_arg(ap, php_var);
        if(key2 == -1)
        {
            bool found = false;
            for(;;)
            {
                for(i = 0;i < arr.keys.size(); ++i)
                {
                    if(arr.keys[i] == (php_var) i)
                        found = true;
                }
                if(found)
                    ++i;
                else
                    break;
            }
            key2 = i;
        }
        php_var val = va_arg(ap, php_var);
        arr.keys.push_back(key2);
        arr.data.push_back(val);
    };
    va_end(ap);
    return arr;
}

gcc エラー:

id31.cpp: In function ‘php_var substr(php_var, php_var, php_var)’:
id31.cpp:511: error: ambiguous overload for ‘operator-’ in ‘str.php_var::container.std::basic_string<_CharT, _Traits, _Alloc>::length [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]() - pos’
id31.cpp:511: note: candidates are: operator-(size_t, int) <built-in>
id31.cpp:511: note:                 operator-(size_t, double) <built-in>
id31.cpp:511: note:                 operator-(size_t, float) <built-in>
id31.cpp:511: note:                 operator-(size_t, unsigned int) <built-in>
id31.cpp:511: note:                 operator-(size_t, long int) <built-in>

関連コード:

php_var substr(php_var str, php_var pos, php_var len)
{
    if(len == 0)
        len = str.container.length() - pos;
    return (php_var) str.container.substr(pos, len);
}
php_var substr(php_var str, long pos, long len)
{
    if(len == 0)
        len = str.container.length() - pos;
    return (php_var) str.container.substr(pos, len);
}

gcc エラー:

id31.cpp:592: error: ambiguous overload for ‘operator-’ in ‘_length - strlen(php_var)()’
id31.cpp:592: note: candidates are: operator-(const char*, const char*) <built-in>
id31.cpp:592: note:                 operator-(const char*, int) <built-in>
id31.cpp:592: note:                 operator-(const char*, int) <built-in>
id31.cpp:592: note:                 operator-(const char*, int) <built-in>
id31.cpp:592: note:                 operator-(int, int) <built-in>
id31.cpp:592: note:                 operator-(int, double) <built-in>
id31.cpp:592: note:                 operator-(int, float) <built-in>
id31.cpp:592: note:                 operator-(int, unsigned int) <built-in>
id31.cpp:592: note:                 operator-(int, long int) <built-in>
id31.cpp:592: note:                 operator-(double, int) <built-in>
id31.cpp:592: note:                 operator-(double, double) <built-in>
id31.cpp:592: note:                 operator-(double, float) <built-in>
id31.cpp:592: note:                 operator-(double, unsigned int) <built-in>
id31.cpp:592: note:                 operator-(double, long int) <built-in>
id31.cpp:592: note:                 operator-(float, int) <built-in>
id31.cpp:592: note:                 operator-(float, double) <built-in>
id31.cpp:592: note:                 operator-(float, float) <built-in>
id31.cpp:592: note:                 operator-(float, unsigned int) <built-in>
id31.cpp:592: note:                 operator-(float, long int) <built-in>
id31.cpp:592: note:                 operator-(unsigned int, int) <built-in>
id31.cpp:592: note:                 operator-(unsigned int, double) <built-in>
id31.cpp:592: note:                 operator-(unsigned int, float) <built-in>
id31.cpp:592: note:                 operator-(unsigned int, unsigned int) <built-in>
id31.cpp:592: note:                 operator-(unsigned int, long int) <built-in>
id31.cpp:592: note:                 operator-(long int, int) <built-in>
id31.cpp:592: note:                 operator-(long int, double) <built-in>
id31.cpp:592: note:                 operator-(long int, float) <built-in>
id31.cpp:592: note:                 operator-(long int, unsigned int) <built-in>
id31.cpp:592: note:                 operator-(long int, long int) <built-in>

関連コード:

php_var _recruit = _length - (php_var)strlen(_flag);
if (_recruit < (php_var)1)
{
    return _flag;

_end_18:
    return (php_var)sprintf((string)(const char*)(php_var)"%0" + (string)(const char*)_length + (string)(const char*)(php_var)"d", _flag);

}

gcc エラー:

id31.cpp:598: error: cannot convert ‘std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘char*’ for argument ‘1’ to ‘int sprintf(char*, const char*, ...)’

関連コード:

if (_recruit < (php_var)1)
{
    return _flag;

_end_18:
    return (php_var)sprintf((string)(const char*)(php_var)"%0" + (string)(const char*)_length + (string)(const char*)(php_var)"d", _flag);

}
4

3 に答える 3

4
  1. php_var可変個引数関数のパラメーターとしてオブジェクトを渡しますphp_var array(int key = 0, ...)。これは許可されていません。可変個引数パラメーターとして渡すことができるのは、PODオブジェクトのみです。

  2. および3. (またはタイプ、それがどのタイプかわからない)と。のoperator-間に定義はありません。int_lengthphp_var

  3. sprintfchar*あなたがそれに渡す間、最初の引数として、を取りますstd::stringstd::string::c_str()文字列をに変換するために使用しますconst char*

于 2011-02-07T15:02:46.927 に答える
2

最初のエラーは単純です。型のオブジェクトをphp_var可変個引数パラメーター(特定のパラメーターである関数へ...のパラメーター)として渡すことはできません。

php_varその他のエラーについては、それ自体の定義を見ずに言うのは難しいです。

あなたが書くときに一体何を意図しているのですか:(string)(const char*)(php_var)"%0"?!

文字列を取得し、それを不明なタイプにキャストしから、(最初は)にキャストし直してから、 (に渡すことができないconst char*)に強制します...なぜですか?std::stringprintf

最後の2つのスニペットは、パラメータにの長さ属性を指定させようとしているように見えprintfます。そのマニュアルページを見ると、これを行うのが適切な方法であることがわかりますprintf("%*d", width, num);*「width」オプションが期待される場所にaを配置するだけで、printf渡された別のパラメーターからそれを取得するように指示されます。

最後に、実行しているキャストはすべて、本当に悪いコードの兆候です。正しく実行すると、キャストは非常にまれにしか発生しません。

于 2011-02-07T15:04:16.327 に答える
2

POD =>プレーンな古いデータ:varargsはC言語用に作成されており、コンストラクタ/デストラクタを含まない上部構造でのみ使用できます。

于 2011-02-07T15:06:00.803 に答える