overload

C++ ambiguous overload for ‘operator ’

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'v read several posts here about this kind of errors, but I wasn't able to solve this one... Has soon I define the operator int and the function f, fails to compile. I tested several things by I wasn't able to solve the issue.... Thanks ex1.cpp: In function ‘int main(int, char**)’: ex1.cpp:35:13: error: ambiguous overload for ‘operator+’ in ‘a + 4’ ex1.cpp:35:13: note: candidates are: ex1.cpp:35:13: note: operator+(int, int) <built-in> In file included from ex1.cpp:3:0: Fraccao.h:41:9: note: Fraccao operator+(const Fraccao&, const Fraccao&)

function overload and type conversion resolution

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: why do we not see a "undefined call to overloaded function" error with the code bellow? just because int is a built in type? where in the standard can I find the guarantee for the conversion to built in type, such as in the code bellow?... thanks! #include <iostream> using namespace std; class B { public: operator int(){ return 0; } }; class A { public: A( int i ) { }; }; void f ( int i ) { cout << "overload f(int) was used!";}; void f ( A a ) { cout << "overload f(A) was used!" ;}; int main () { B b; f( b ); } 回答1: It has nothing to do with

Overload * operator in python (or emulate it)

匿名 (未验证) 提交于 2019-12-03 08:56:10
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to overload the * operator in python. In C++, you can overload the dereference operator, so that you can create a class with a custom way to respond to *alpha . Part of this question is that I don't know exactly, and I mean EXACTLY, what the * operator (unpacking operator as I call it) does. So how can I overload it, or emulate the overloading of it. Eventually I want to be able to do: *alpha with a custom response and return value. EDIT: I found the solution thanks to Joe Kington's comment. As *alpha unpacks according to __iter__ ,

Is it possible to overload operator associativity in C++?

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm building a class that has a slightly asymmetric addition. Before the complaints come in, it's necessarily asymmetric. There is a conversion (operation that takes a bit of time) that has to happen when two objects are added together, and the conversion most naturally happens with respect to the right summand. To make this concrete, here's a generic example of what's going on... class Foo { char _fav ; int _prop ; public : const char fav () const { return _fav ;} const int prop () const ( return _prop ;} void changeFav ( char );

std::transform() and toupper(), no matching function

匿名 (未验证) 提交于 2019-12-03 08:51:18
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I tried the code from this question C++ std::transform() and toupper() ..why does this fail? #include #include int main() { std::string s="hello"; std::string out; std::transform(s.begin(), s.end(), std::back_inserter(out), std::toupper); std::cout Theoretically it should've worked as it's one of the examples in Josuttis' book, but it doesn't compile http://ideone.com/aYnfv . Why did GCC complain: no matching function for call to ‘transform( __gnu_cxx::__normal_iterator , std::allocator > >, __gnu_cxx::__normal_iterator , std::allocator > >,

In Web API, how do you overload Get when one method contains with nullable value types as parameters

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: UPDATE My original assumption was that optional parameters were the cause of the problem. That appears to be incorrect. Instead, it appears to be a problem with multiple action methods when one of those methods contains nullable value types (e.g. int? ) for some of the parameters. I'm using Visual Studio 2012 RC and am just getting started with Web API. I've run into an issue and getting the error "No action was found on the controller 'Bars' that matches the request." I've got a Bars controller. It has a Get() method that takes in optional

c# generic method overload not consistent with abstract Visitor pattern

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: experimenting with Visitor pattern and generic method I found a kind of discrepancy in C#.NET. AFAIK C# compiler prefers an explicit overload to a generic method, therefore the following code: public abstract class A { public abstract void Accept(Visitor v); } public class B : A { public override void Accept(Visitor v) { v.Visit(this); } } public class C : A { public override void Accept(Visitor v) { v.Visit(this); } } public class D : A { public override void Accept(Visitor v) { v.Visit(this); } } public class Visitor { public void Visit(B

Overload resolution gets different result between gcc and clang

匿名 (未验证) 提交于 2019-12-03 08:42:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: struct A { A(int);}; struct B { explicit B(A); B(const B&);}; B b({0}); gcc 5.1.0 gives the error /dev/fd/63:3:8: error: call of overloaded 'B(<brace-enclosed initializer list>)' is ambiguous /dev/fd/63:3:8: note: candidates are: /dev/fd/63:2:27: note: B::B(const B&) /dev/fd/63:2:21: note: B::B(A) while clang 3.6.0 succeeds. Which one is right? Why? For gcc 5.1.0: http://melpon.org/wandbox/permlink/pVe9eyXgu26NEX6X For clang 3.6.0: http://melpon.org/wandbox/permlink/WOi1md2dc519SPW0 This may be similar to Direct list initialization compiles

In Ruby is there a way to overload the initialize constructor?

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Java you can overload constructors: public Person(String name) { this.name = name; } public Person(String firstName, String lastName) { this(firstName + " " + lastName); } Is there a way in Ruby to achieve this same result: two constructors that take different arguments? 回答1: The answer is both Yes and No. You can achieve the same result as you can in other languages using a variety of mechanisms including :- Default values for arguments Variable Argument lists (The splat operator) Defining your argument as a hash The actual syntax of the

“No overload for method &#039;LabelFor&#039; takes 2 arguments” in MVC3

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm running ASP.NET MVC 3 and I'm looking at a Edit view for my model. I've got a FullName property which I want to render as "Full name". Here's the offending line(s): <div class="display-label"> <%: Html.LabelFor(model => model.FullName, "Full name") %> </div> Now the intellisense shows that the overload exists - there are two signatures, the first taking just the Expression and the second taking both the Expression and the string to be displayed. However when I browse to the page I get the titled exception ('no overload...'). Anyone have