如果我有两个变量,a并且b,std::max(a,b)返回更高的价值.
是否有可能让这个函数修改哪个变量更大,即if x是第三个变量,
max(a,b) = x;
Run Code Online (Sandbox Code Playgroud)
a==x如果此次通话持有,a则大于b,否则b==x?
如何在不收到警告的情况下返回对象的引用:
std::string& GetString()
{
std::string str = "Abcdefghijklmnopqrstuvwxyz";
return str;
}
int main()
{
std::string str = GetString();
}
Run Code Online (Sandbox Code Playgroud)
这会导致对恭维的警告.
我需要std::vector在32位中存储大量元素(更多是unsigned int允许的2 ^ 32-1).据我所知,这个数量受std::size_tunsigned int类型的限制.我可以std::size_t通过铸造来改变这个unsigned long吗?它能解决问题吗?
如果那是不可能的,假设我用64位编译.这会解决问题而不做任何修改吗?
我可以在现有类中重载现有的函数/运算符吗?
我试图这样做:
#include <iostream>
#include <string>
using namespace std;
string& string::operator<<(const string& str) {
this->append(str);
}
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:
test.cpp:5: error: too few template-parameter-lists
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?或者我不能?
似乎与成员函数不同,您无法指定要使用的memory_order,因此可能会有一些"默认"最终被使用.
嗨,我有以下代码:
char msg[10000];
string mystr = "hello";
Run Code Online (Sandbox Code Playgroud)
我想将 mystr 放入 msg 中。有没有办法做到这一点?我尝试了各种方法,但不断得到:
incompatible types in assignment of 'const char*' to char [10000]'
Run Code Online (Sandbox Code Playgroud)
我试过:
msg = mystr.c_str();
Run Code Online (Sandbox Code Playgroud)
和
msg = (char[10000])mystr;
Run Code Online (Sandbox Code Playgroud)
无济于事。
我发现了一些C++ 11的功能并且有问题.我有一个成员函数'call'
class cscript
{
public:
template <typename ret_t, typename... params>
bool call(ret_t &ret, const char * name, params... parameters);
....
Run Code Online (Sandbox Code Playgroud)
执行:
template <typename ret_t, typename... params>
bool cscript::call(ret_t &ret, const char * name, params... parameters)
{
ret_t (*func)(params...);
func = (decltype(func)) tcc_get_symbol(tcc, name);
if (!func)
return true;
ret = func(parameters...);
return false;
}
Run Code Online (Sandbox Code Playgroud)
链接时显示以下错误:
obj\Release\main.o:main.cpp:(.text.startup+0xcc)||undefined reference to `bool cscript::call<int, int, int>(int&, char const*, int, int)'|
Run Code Online (Sandbox Code Playgroud)
电话示例:
script.call(ret, "sum", 2, 3);
Run Code Online (Sandbox Code Playgroud)
有关如何使这项工作的任何建议?
我在linux上使用GCC 4.1.2,STL必须是SGI STL.我写完之后:
#include <functional>
std::find_if(PirateFlush, PirateFlush + size,
compose2(std::logical_and<bool>(), bind2nd(std::greater<UInt32>(), time),
bind2nd(std::less<UInt32>(), now)));
Run Code Online (Sandbox Code Playgroud)
编译说:
错误:'compose2'未在此范围内声明
怎么了?
我有strValue作为NSString,我想复制strValueS含量"到另一个地方.
这个地方是mstrValue,这是NSMutableString.空间mstrValue已经分配.
我想知道我如何使用memcpy或strcpy为此目的.
如果不可能,我想知道其他方法.
我正在尝试对一个相当大的项目进行一个Instrumentation Profiling(在整个解决方案中大约40,000个源文件,但是在分析中的项目有大约200个源文件),用C++编写.
每次我运行分析时,它会创建一个大约34GB的巨大报告,然后,当它要分析它时,它正在尝试(我认为)将整个文件加载到RAM中.
显然,它使计算机无法使用,我必须在分析仪完成之前停止它.
有什么建议?