gpt4 book ai didi

c++ - 试图克服这 6 个 g++ 错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:30 25 4
gpt4 key购买 nike

这些是 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);

}

最佳答案

  1. 您正在传递一个 php_var 对象作为可变函数 php_var array(int key = 0, ...) 的参数。这是不允许的。只有 POD 对象可以作为可变参数传递。

  2. 和3.int之间没有定义operator-(或者_length的类型,不知道是什么输入它是)和一个 php_var

  3. sprintfchar* 作为第一个参数,而您将 std::string 传递给它.使用 std::string::c_str() 将您的字符串转换为 const char*

关于c++ - 试图克服这 6 个 g++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4922673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com