我正在尝试使用 Visual Studio 2010 (C++) 编译 QtScriptGenerator ( gitorious ),但遇到了编译错误。在寻找解决方案的过程中,我偶尔会看到自 VS2008 以来由于 VS2010 的 STL 实现的变化和/或 c++0x 一致性变化而引入的编译破损。
知道下面发生了什么,或者我该如何解决它?如果有问题的代码似乎是 QtScriptGenerator 的,我想我会更容易修复它。但在我看来,有问题的代码可能在 VS2010 的 STL 实现中,我可能需要创建一个解决方法?
附言。我对模板和 STL 很陌生。我有嵌入式和控制台项目的背景,这些项目直到最近才经常被避免以减少内存消耗和交叉编译器风险。
编辑 - 看起来可能是 Visual Studio 对 std::copy 的实现发生了变化。
C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(275) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'rpp::pp_output_iterator<_Container>' (or there is no acceptable conversion)
with
[
_Container=std::string
]
c:\qt\qtscriptgenerator\generator\parser\rpp\pp-iterator.h(75): could be 'rpp::pp_output_iterator<_Container> &rpp::pp_output_iterator<_Container>::operator =(const char &)'
with
[
_Container=std::string
]
while trying to match the argument list '(rpp::pp_output_iterator<_Container>, rpp::pp_output_iterator<_Container>)'
with
[
_Container=std::string
]
C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(2176) : see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
with
[
_Iter=rpp::pp_output_iterator<std::string>,
_OutIt=rpp::pp_output_iterator<std::string>,
_UIter=rpp::pp_output_iterator<std::string>
]
c:\qt\qtscriptgenerator\generator\parser\rpp\pp-internal.h(83) : see reference to function template instantiation '_OutIt std::copy<std::_String_iterator<_Elem,_Traits,_Alloc>,_OutputIterator>(_InIt,_InIt,_OutIt)' being compiled
with
[
_OutIt=rpp::pp_output_iterator<std::string>,
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>,
_OutputIterator=rpp::pp_output_iterator<std::string>,
_InIt=std::_String_iterator<char,std::char_traits<char>,std::allocator<char>>
]
c:\qt\qtscriptgenerator\generator\parser\rpp\pp-engine-bits.h(500) : see reference to function template instantiation 'void rpp::_PP_internal::output_line<_OutputIterator>(const std::string &,int,_OutputIterator)' being compiled
with
[
_OutputIterator=rpp::pp_output_iterator<std::string>
]
C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(275) : error C2582: 'operator =' function is unavailable in 'rpp::pp_output_iterator<_Container>'
with
[
_Container=std::string
]
这里有一些背景......
#ifndef PP_INTERNAL_H
#define PP_INTERNAL_H
#include <algorithm>
#include <stdio.h>
namespace rpp {
namespace _PP_internal
{
..
64 template <typename _OutputIterator>
65 void output_line(const std::string &__filename, int __line, _OutputIterator __result)
66 {
67 std::string __msg;
68
69 __msg += "# ";
70
71 char __line_descr[16];
72 pp_snprintf (__line_descr, 16, "%d", __line);
73 __msg += __line_descr;
74
75 __msg += " \"";
76
77 if (__filename.empty ())
78 __msg += "<internal>";
79 else
80 __msg += __filename;
81
82 __msg += "\"\n";
83 std::copy (__msg.begin (), __msg.end (), __result);
84 }
#ifndef PP_ENGINE_BITS_H
#define PP_ENGINE_BITS_H
#include <stdio.h>
namespace rpp {
450 template <typename _InputIterator, typename _OutputIterator>
451 void pp::operator () (_InputIterator __first, _InputIterator __last, _OutputIterator __result)
452 {
..
497 if (env.current_line != was)
498 {
499 env.current_line = was;
500 _PP_internal::output_line (env.current_file, env.current_line, __result);
501 }
.. 这是 pp_output_iterator
的定义#ifndef PP_ITERATOR_H
#define PP_ITERATOR_H
#include <iterator>
namespace rpp {
..
template <typename _Container>
class pp_output_iterator
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
std::string &_M_result;
public:
explicit pp_output_iterator(std::string &__result):
_M_result (__result) {}
inline pp_output_iterator &operator=(typename _Container::const_reference __v)
{
if (_M_result.capacity () == _M_result.size ())
_M_result.reserve (_M_result.capacity () << 2);
_M_result.push_back(__v);
return *this;
}
inline pp_output_iterator &operator * () { return *this; }
inline pp_output_iterator &operator ++ () { return *this; }
inline pp_output_iterator operator ++ (int) { return *this; }
};
最佳答案
我认为问题在于 std::copy正在尝试在您的 operator=() 上使用“复制分配”(rpp::pp_output_iterator<>)并且没有 operator=()对于那个类模板。我应该说,有一个 operator=()但它没有采用正确的参数作为“复制赋值”函数(即,它不采用 ``rpp::pp_output_iterator<>& parameter). I think that the existence of some operator=()` 函数将阻止编译器生成一个默认值(我目前无法访问标准文档来 100% 验证这一点)。
请注意,一个类型必须是可赋值的(当然,除其他事项外)才能被视为 OutputIterator:http://www.sgi.com/tech/stl/OutputIterator.html
以前版本的 std::copy在 MSVC 中可能实际上没有使用赋值(仅仅因为 OutputIterator 必须支持它并不意味着 std::copy 必须使用它),这就是为什么它可能是 VS2010 中的"new"错误。 (由于我的工具访问受限,我现在无法检查)。
关于c++ - STL operator= Visual Studio 2010 的行为发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2791525/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden
在启用Rack::Deflater来gzip我的响应主体时偶然发现了一些奇怪的东西。也许我遗漏了一些东西,但启用此功能后,响应被压缩,但是资源的ETag在每个请求上都会发生变化。这会强制应用程序每次都响应,而不是发送304。这在没有启用Rack::Deflater的情况下有效,我已经验证页面源没有改变。我正在运行一个使用thin作为Web服务器的Rails应用程序。Gemfile.lockhttps://gist.github.com/2510816有没有什么方法可以让我从Rack中间件获得更多的输出,这样我就可以看到发生了什么?提前致谢。 最佳答案
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
两个gsub产生不同的结果。谁能解释一下为什么?代码也可在https://gist.github.com/franklsf95/6c0f8938f28706b5644d获得.ver=9999str="\tCFBundleDevelopmentRegion\n\ten\n\tCFBundleVersion\n\t0.1.190\n\tAppID\n\t000000000000000"putsstr.gsub/(CFBundleVersion\n\t.*\.).*()/,"#{$1}#{ver}#{$2}"puts'--------'putsstr.gsub/(CFBundleVersio
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
所以我想到了这个,想知道当下面的一些事情完成后会发生什么。classTestdefself.abcattr_accessor:Johnendendobject=Test.newputs"beforecallingclassmethodabc:#{object.class.instance_methods(false)}"Test.abcputs"aftercallingclassmethodabc:#{object.class.instance_methods(false)}"这里我检查的是,getter和setter方法是否以这种方式创建。如果是这样,是那些实例方法或类方法。首先我创
我在一段非常简单的代码(如我所想)中得到了一个错误的值:org=4caseorgwhenorg=4val='H'endputsval=>nil请不要生气,我希望我错过了一些非常明显的东西,但我真的想不通。谢谢。 最佳答案 这是典型的Ruby错误。case有两种被调用的方法,一种是你传递一个东西作为分支的基础,另一种是你不传递的东西。如果您确实在case中指定了一个表达式语句然后评估所有其他条件并与===进行比较.在这种情况下org评估为false和org===false显然不是真的。所有其他情况也是如此,它们要么是真的,要么是假的。
假设您在Ruby中执行此操作:ar=[1,2]x,y=ar然后,x==1和y==2。是否有一种方法可以在我自己的类中定义,从而产生相同的效果?例如rb=AllYourCode.newx,y=rb到目前为止,对于这样的赋值,我所能做的就是使x==rb和y=nil。Python有这样一个特性:>>>classFoo:...def__iter__(self):...returniter([1,2])...>>>x,y=Foo()>>>x1>>>y2 最佳答案 是的。定义#to_ary。这将使您的对象被视为要分配的数组。irb>o=Obje
我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“