草庐IT

scope-chain

全部标签

c++ - GNU 编译器 vs. Visual Studio 在数组上分配 w/Length Constant w/in a Scope

我知道如果你在c/c++中设置一个动态值,你不能在括号内使用该值来分配一个数组(这会使它成为所谓的可变长度数组(VLA),其中currentC++standard不支持)...即见:C++:VariableLengthArrayhttp://en.wikipedia.org/wiki/Variable-length_array我不太明白(而且我在这里没有看到确切地问到的)是为什么GNUc/c++编译器(gcc、g++)没问题使用基于整数值的动态分配(据我所知),只要该值是数组分配范围内的常量,但VisualStudio不支持这一点并且将拒绝编译代码,吐出错误。例如在g++中voidFo

c++ - boost::scoped_lock 不适用于局部静态变量?

我制作了以下示例程序来使用boost线程:#pragmaonce#include"boost\thread\mutex.hpp"#includeclassThreadWorker{public:ThreadWorker(){}virtual~ThreadWorker(){}staticvoidFirstCount(intthreadId){boost::mutex::scoped_lock(mutex_);staticinti=0;for(i=1;i主类://ThreadTest.cpp#include"stdafx.h"#include"boost\thread\thread.hpp

c++ - "Function not declared in this scope"编译openCV代码出错

我正在尝试编写一些使用openCV函数的代码。我从文档中提供的一些示例代码开始:#include#include#includeusingnamespacecv;usingnamespacestd;intmain(intargc,char**argv){if(argc!=2){cout当我尝试在Eclipse-CDT中构建它时,我得到了这个:****BuildofconfigurationDebugforprojectopenCV1****makeallBuildingtarget:openCV1Invoking:CrossG++Linkerg++-L/usr/local/lib-o"

c++ - (C++) 错误 : 'invalid_argument' was not declared in this scope

我正在使用EclipseC/C++和MinGW编译器。我已将标志-std=c++11添加到项目属性中C/C++Build下的MiscellaneousGCCCCompilerSettings中。我知道这可能是一件简单的事情,但我无法解决此错误。Date.h#includeusingnamespacestd;classDate{public:Date(intm=1,intd=1,inty=1900);voidsetDate(int,int,int);private:intmonth;intday;intyear;staticconstintdays[];};日期.cpp#include#

c++ - C++ 中的 "Variable ' i ' was not declared in scope "是什么?

在练习C++代码时,我使用了在for循环中声明的变量。我希望它在另一个for循环中再次使用它。但它向我显示了一个错误,即variableiwasnotdeclaredinscope我在EclipseIDE中尝试了相同的循环thesymboliwasnotresolved.示例代码与此类似:#includeusingnamespacestd;intmain(){for(inti=0;i 最佳答案 您必须为每个范围声明变量:#includeusingnamespacestd;intmain(){for(inti=0;i在第一个循环之后,

c++ - C++11 中的 BOOST scoped_lock 替换

我面临这样一种情况,我必须用C++11中的等效项替换BOOSTscoped_lock。在visualstudio2013下。由于c++11不支持scoped_lock,我不确定下面的替换代码是什么。我应该选择lock_guard还是try_lock?boost::mutex::scoped_lockobjectLock(ObjectVectorMutex,boost::try_to_lock);if(objectLock){//...}在代码中我有以下“等待”语句if(ObjectsCollection.empty()){//Thisiswherewewaittilsomethingi

c++ - 在类 : scoped_ptr or shared_ptr? 中将智能指针作为参数传递

我有一个类在一个公共(public)方法中创建一个对象。该对象是私有(private)的,对类的用户不可见。此方法然后调用同一类中的其他私有(private)方法并将创建的对象作为参数传递:classFoo{...};classA{private:typedefscoped_ptrFooPtr;voidprivateMethod1(FooPtrfooObj);public:voidshowSomethingOnTheScreen(){FooPtrfooObj(newFoo);privateMethod1(fooObj);};};我相信在这种情况下正确的智能指针将是一个scoped_pt

c++ - 在简单的情况下使用 scoped_ptr 是否有点矫枉过正?

我在像这样的小函数中使用scoped_ptr。这样我就不必调用delete了。这是这种用法的矫枉过正吗?我的团队成员更喜欢原始指针和删除。如果这恰好用在非常关键的路径中,那么使用scoped_ptr的成本是多少?这不应该是内联的并且完全等同于在优化的二进制文件中使用普通删除吗?voidmyfunc(){boost::scoped_ptrobjptr=someFactory::allocate();callsomeotherfunc(objptr.get());} 最佳答案 我不确定对性能的影响,但是在这里使用scoped_ptr确保

c++ - 应该使用哪个 header 来使用 scoped_ptr

我想在我的C++应用程序中使用智能指针。使用stdscoped_ptr应该包含哪个头文件? 最佳答案 标准C++库中没有scoped_ptr。全部C++11smartpointers在标题中.如果你想要boost::scoped_ptr那么你需要boost/scoped_ptr.hpp. 关于c++-应该使用哪个header来使用scoped_ptr,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/q

C++ 错误 : ‘_mm_sin_ps’ was not declared in this scope

我正在尝试对将函数应用于数组的不同方法进行基准测试。为什么是https://software.intel.com/sites/landingpage/IntrinsicsGuide/#expand=3260,2124,4779,4779&cats=Trigonometry&text=_sin_mm_sin_ps在我的范围内未知,但_mm_sqrt_ps是?我如何让它为人所知?并编译无误。#include#include#include#include#include#include#include"immintrin.h"#includeintmain(){std::coutdis(-