本文介绍了在我爆炸之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! G ++提供了最无信息,最神秘,更糟糕的BULLSHIT错误 语句。 我现在正在写一个程序而且我有完成它 很快。我所遇到的问题在 下面说明: class Blah { private: int k; public: operator int() { 返回k; } }; int main() { Blah const poo; switch(poo) { 案例1: ; } } 切换语句中的yokie必须是 整数类型。我的班级有一个operator int()。盛大。 请注意poo对象是const。如果我使poo 对象非const,那么上面的代码编译。但是什么 HELL的差异在于它是否会变得很好! 请一些启示, -JKopG++ gives the most un-informative, cryptic, BULLSHIT errorsstatements.I''m writing a program at the moment and I have to finish itreal soon. The problem I''m having is illustrated in thefollowing:class Blah{private:int k;public:operator int(){return k;}};int main(){Blah const poo;switch (poo){case 1:;}}The yokie that goes in a switch statement has to be anintegral type. My class has an "operator int()". Grand.Note that the "poo" object is const. If I make the pooobject non-const, then the above code compiles. BUT WHATTHE HELL DIFFERENCE DOES IT MAKE IF IT''S CONST!Some enlightenment please,-JKop推荐答案 operator const int() - Ioannis Vranos http://www23.brinkster.com/noicys operator const int() operator const int() 这是我的第一个想法。 流血的东西仍然不起作用! 单词编译器错误我想到了...... 无论如何, 运算符int()返回* value *,所以它会没有 如果对象是const还是不同的话。 我能看到能够定义两者的唯一原因: operator int() 和 运算符const int() 是有单独的例程在const上工作不同对象对普通对象。 我可以把程序写成五次如果我 没有必要处理这个废话。 现在,我正在通过以下方式解决这个问题: Blah temp(poo); 开关(临时) 直到我弄清楚到底是怎么回事! /> -JKop -JKopThat was my first thought.The bleeding thing still doesn''t work!The words "compiler bug" are coming to mind...Anyway,the operator int() returns by *value*, so it would make nodifference whatsoever if the object was const or not.The only reason I can see of being able to define both:operator int()andoperator const int()is to have separate routines that work differently on constobjects Vs normal objects.I could have the program written five times already if Ididn''t have to deal with this bullshit.Right now, I''m getting around it via:Blah temp(poo);switch (temp)That''s until I figure out what the hell''s going on!-JKop-JKop - Ioannis Vranos http://www23.brinkster.com/noicys 这篇关于在我爆炸之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-25 02:18