草庐IT

cross_val_score

全部标签

异常情况下的 C++ 错误 C2228( '.val' 左侧必须有类/结构/union )

在C++中,我正在尝试实现自己的any使用C++的类。然而,在我能够对其进行测试之前(如果我的实现不好,请随时纠正我),我得到了错误:errorC2228:leftof'.val'musthaveclass/struct/union使用value()两次功能两次,当它在其他地方工作时,这看起来很奇怪。我唯一能想到的就是decltype函数前面导致错误,但它不应该:编辑:我更新了为templateany(TV){...}更改变量的方式构造函数classany{protected:templatestructvariable{public:Tval;variable(){}variable

c++ - const decltype(*std::begin(container))& val 不会使 val const?

这段代码:std::vectorints(5,1);std::for_each(ints.begin(),ints.end(),[](constdecltype(*std::begin(ints))&val){val*=2;});在VisualStudio2010中编译和运行得很好,并且修改容器中的每个值,就像没有const关键字一样。这是编译器中的错误吗,因为预期的行为是val是不可修改的?(换句话说,我希望它不会编译,但它会编译)更新:std::for_each(ints.begin(),ints.end(),[](conststd::remove_reference::type&

c++ - "crosses initialization of variable"仅当初始化结合声明时

我读过thisquestion关于“跳转到案例标签”错误,但我还有一些疑问。我在Ubuntu12.04上使用g++4.7。这段代码报错:intmain(){intfoo=1;switch(foo){case1:inti=0;i++;break;case2:i++;break;}}错误是jump-to-case-label.cpp:Infunction‘intmain()’:jump-to-case-label.cpp:8:8:error:jumptocaselabel[-fpermissive]jump-to-case-label.cpp:5:9:error:crossesinitia

c++ - if((int val = getvalue()) == x) 表格是否应该工作

此表单无法使用我的VS2008编译器进行编译。应该可以吗?#includeusingnamespacestd;intgetvalue(){return3;}intmain(intargc,char*argv[]){if((intval=getvalue())==3)cout这个表格确实有效。...intval;if((val=getvalue())==3)...为什么不起作用? 最佳答案 这是不合法的,因为你不能将语句用作表达式。因此,不是在if中声明变量是非法的,而是比较。就像:(intx=3)==3;是非法的,而intx=3;x

c++ - std::vector<T>::resize( n, val ) 是否足以进行初始化?

这是一个特定于C++11的问题。假设我有一个vectorstd::vectorv已经使用过,我想将其调整为n使用现有值初始化的元素Tval.(典型用例:vector是被回收实例的成员)。以下几种方式各有什么优缺点,哪种方式效率最高?1)是std::vector::resize(n,val)足以进行初始化吗?v.clear();v.resize(n,val);2)如果不是,那么我假设以下是正确的?v.clear();v.resize(n);std::fill(v.begin(),v.end(),val);3)交换怎么样?v.swap(std::vector(n,val));

c++ - 错误 : jump to label 'foo' crosses initialization of 'bar'

以下C++示例无法使用gcc或clang进行编译,但仅使用ICC生成警告,而使用MSVC则完全不生成任何警告:intmain(intargc,char*argv[]){if(argcg++:init.cpp:13:error:jumptolabel‘clean_up’init.cpp:4:error:fromhereinit.cpp:7:error:crossesinitializationof‘inti’clang++:init.cpp:4:9:error:cannotjumpfromthisgotostatementtoitslabelgotoclean_up;^init.cpp:

c++ - 具有模板特化的 constexpr 数组成员 : inconsistent behavior cross compilers

考虑以下代码:#includetemplatestructfoo{};templatestructfoo{staticconstexprcharvalue[]="abcde";};templatestructbar{staticconstexprcharvalue[]="abcde";};templatestructbaz{staticconstexprintvalue=12345;};intmain(){charc=foo::value[2];chard=bar::value[2];inte=baz::value;std::cout编译时:clang++-std=c++14./tes

c++ - G++ CAS (__sync_val_compare_and_swap) 问题需要解释

这让我很头疼。我正在尝试实现一些“无锁”代码并使用CAS(gcc__sync_val_compare_and_swap)来完成繁重的工作。我的问题可以用下面的代码显示。volatileboollock;void*locktest(void*arg){for(inti=0;i好的,如果我在10个并发线程中运行上面的代码,一切都很好。但是,如果我将代码改为阅读//acquirealockwhile(__sync_val_compare_and_swap(&lock,lock,true)==true)请注意,我已将“false”更改为“lock”。一切都乱套了,断言//makesureweh

c++ - 如何编写具有 cout 样式接口(interface)的记录器类 (logger << "Error: "<< val << endl;)

我想创建一个具有如下功能的记录器类:Loggerlog;log这应该给我打印一条自定义格式的消息。例如。“12-09-200911:22:33看到错误5”我的简单类目前看起来像这样:classLogger{private:ostringstreamoss;public:templateLogger&operatorLogger&Logger::operator这将导致oss正确地拥有缓冲区“Error:5seen”。但我不知道我还需要编写/修改什么其他功能才能在屏幕上打印某些内容。有谁知道如何让它工作,或者是否有另一种方法来设计这个类来让我的功能正常工作?

开发安全之:Cross-Site Scripting: DOM

Overview方法setDestination()向Web浏览器发送非法数据,从而导致浏览器执行恶意代码。DetailsCross-SiteScripting(XSS)漏洞在以下情况下发生:1.数据通过一个不可信赖的数据源进入Web应用程序。对于基于DOM的XSS,将从URL参数或浏览器中的其他值读取数据,并使用客户端代码将其重新写入该页面。对于ReflectedXSS,不可信赖的数据源通常为Web请求,而对于Persisted(也称为Stored)XSS,该数据源通常为数据库或其他后端数据存储。2.未经验证但包含在动态内容中的数据将传送给Web用户。对于基于DOM的XSS,任何时候当受害人