草庐IT

implicit-conversion

全部标签

c++ - return 语句何时需要显式 move ?

在commenttoanotherquestion中JonathanWakely回应我的声明:Youneverneedexplicitmoveforalocalvariablefunctionreturnvalue.It'simplicitmovethere->...neversaynever...Youneedanexplicitmoveifthelocalvariableisnotthesametypeasthereturntype,e.g.std::unique_ptrf(){autop=std::make_unique();p->foo();returnp;},butifthe

c++ - srand (time (null)) 导致编译器警告 : implicit conversion loses integer precision

如果这个问题已经得到解答,我们深表歉意。#include#include#includeusingnamespacestd;intmain(){srand(time(NULL));cout“隐式转换丢失整数精度:'time_t'(又名'long')到'unsignedint'”是我在执行上面的代码时收到的错误消息。我正在使用xcode4.6.1。现在,当我使用不同的编译器(例如来自codepad.org的编译器)时,它执行得非常好,生成看起来像随机数的东西,所以我假设这是我需要解决的xcode问题?我刚刚开始编程,所以在这方面我是一个完整的初学者。我的代码有问题还是我的编译器有问题?任

c++ - srand (time (null)) 导致编译器警告 : implicit conversion loses integer precision

如果这个问题已经得到解答,我们深表歉意。#include#include#includeusingnamespacestd;intmain(){srand(time(NULL));cout“隐式转换丢失整数精度:'time_t'(又名'long')到'unsignedint'”是我在执行上面的代码时收到的错误消息。我正在使用xcode4.6.1。现在,当我使用不同的编译器(例如来自codepad.org的编译器)时,它执行得非常好,生成看起来像随机数的东西,所以我假设这是我需要解决的xcode问题?我刚刚开始编程,所以在这方面我是一个完整的初学者。我的代码有问题还是我的编译器有问题?任

c++ - 警告 C4244 : 'argument' : conversion from 'time_t' to 'unsigned int' , 可能丢失数据 -- C++

我制作了一个简单的程序,允许用户选择一些骰子然后猜测结果......我之前发布了这段代码,但有错误的问题,所以它被删除了......现在我不能有任何错误甚至此代码上的警告,但由于某种原因,此警告不断弹出,我不知道如何修复它...“警告C4244:'argument':从'time_t'转换为'unsignedint',可能丢失数据”#include#include#include#includeusingnamespacestd;intchoice,dice,random;intmain(){stringdecision;srand(time(NULL));while(decision

c++ - 警告 C4244 : 'argument' : conversion from 'time_t' to 'unsigned int' , 可能丢失数据 -- C++

我制作了一个简单的程序,允许用户选择一些骰子然后猜测结果......我之前发布了这段代码,但有错误的问题,所以它被删除了......现在我不能有任何错误甚至此代码上的警告,但由于某种原因,此警告不断弹出,我不知道如何修复它...“警告C4244:'argument':从'time_t'转换为'unsignedint',可能丢失数据”#include#include#include#includeusingnamespacestd;intchoice,dice,random;intmain(){stringdecision;srand(time(NULL));while(decision

c++ - 通过隐式转换返回时是否需要复制构造函数?

以下代码在VisualC++2013中编译良好,但在GCC或Clang下编译失败。哪个是正确的?通过隐式转换返回对象时是否需要可访问的复制构造函数?classNoncopyable{Noncopyable(Noncopyableconst&);public:Noncopyable(int=0){}};Noncopyablefoo(){return0;}intmain(){foo();return0;}海合会:error:'Noncopyable::Noncopyable(constNoncopyable&)'isprivateNoncopyable(Noncopyableconst&)

c++ - 通过隐式转换返回时是否需要复制构造函数?

以下代码在VisualC++2013中编译良好,但在GCC或Clang下编译失败。哪个是正确的?通过隐式转换返回对象时是否需要可访问的复制构造函数?classNoncopyable{Noncopyable(Noncopyableconst&);public:Noncopyable(int=0){}};Noncopyablefoo(){return0;}intmain(){foo();return0;}海合会:error:'Noncopyable::Noncopyable(constNoncopyable&)'isprivateNoncopyable(Noncopyableconst&)

C++ 警告 : deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

我正在使用gnuplot在C++中绘制图形。该图正在按预期绘制,但在编译期间出现警告。警告是什么意思?warning:deprecatedconversionfromstringconstantto‘char*’[-Wwrite-strings]这是我正在使用的功能:voidplotgraph(doublexvals[],doubleyvals[],intNUM_POINTS){char*commandsForGnuplot[]={"settitle\"ProbabilityGraph\"","plot'data.temp'withlines"};FILE*temp=fopen("da

C++ 警告 : deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

我正在使用gnuplot在C++中绘制图形。该图正在按预期绘制,但在编译期间出现警告。警告是什么意思?warning:deprecatedconversionfromstringconstantto‘char*’[-Wwrite-strings]这是我正在使用的功能:voidplotgraph(doublexvals[],doubleyvals[],intNUM_POINTS){char*commandsForGnuplot[]={"settitle\"ProbabilityGraph\"","plot'data.temp'withlines"};FILE*temp=fopen("da

c++ - 了解复制初始化和隐式转换

我无法理解为什么以下复制初始化无法编译:#includestructbase{};structderived:base{};structtest{test(std::unique_ptr){}};intmain(){autopd=std::make_unique();//testt(std::move(pd));//thisworks;testt=std::move(pd);//thisdoesn't}一个unique_ptr可以移动到unique_ptr,那么为什么第二个语句有效,而最后一个语句无效?执行复制初始化时是否不考虑非显式构造函数?来自gcc-8.2.0的错误是:conve