overloading

The call is ambiguous between the following methods or properties

不羁岁月 提交于 2019-12-23 06:50:10
问题 Suppose I have these two ctors: public SomeClass(string a, Color? c = null, Font d = null) { // ... } public SomeClass(string a, Font c = null, Color? d = null) { // ... } ~and I do this: SomeClass sc = new SomeClass("Lorem ipsum"); I'll get this: "Error 1 The call is ambiguous between the following methods or properties [...]" It seems apparent to me that it doesn't matter which one I refer to as the end result is the same (at least in this particular case, and to me that's all that matters

C++ - Overload templated class method with a partial specilization of that method

狂风中的少年 提交于 2019-12-23 05:13:09
问题 There are a few questions already similar to this already on stack overflow, but nothing that seemd to directly answer the question I have. I do apologise if I am reposting. I'd like to overload a few methods of a templated class (with 2 template parameters) with a partial template specialisation of those methods. I haven't been able to figure out the correct syntax, and am starting to think that it's not possible. I thought I'd post here to see if I can get confirmation. Example code to

Overloading template by Return Type

若如初见. 提交于 2019-12-23 04:42:16
问题 Mooing Duck makes a comment here that "One function can't return multiple types. However, you can specialize or delegate to overloads, which works fine." I started thinking about that, and I'm trying to figure out, how is this legal code: template <typename T> T initialize(){ return T(13); } When called with: auto foo = initialize<int>(); auto bar = initialize<float>(); Doesn't that translate to 2 functions of the same name overloaded by return-type only? 回答1: It's not an overload, it's a

Segmentation fault when using a shared_ptr

烈酒焚心 提交于 2019-12-23 03:32:14
问题 I am making a particle system and I'm struggling with how to structure my code. The idea is that a user can create one or several ParticleEmitter objects that are passed to a ParticleManager object via the ofxCurlNoise object. Now, I want that when the user updates the ParticleEmitters objects, the ParticleManager object sees the changes made. So I used shared pointers but I have segmentation faults at different times, whether I use one ParticleEmitter (segmentation fault when the program

Virtual assignment operator overloading- how the correct overloaded function is chosen?

送分小仙女□ 提交于 2019-12-22 17:49:05
问题 The following code (from C++ FAQs 24.11) is implementing virtual assignment operator overloading and overriding: #include <iostream> using namespace std; class B{ public: virtual ~B() throw(); virtual B& operator= (const B& b) throw(); }; B::~B() throw(){} B& B::operator= (const B& b) throw() { cout << "B::operator=(const B&)\n"; return *this; } class D : public B{ public: virtual D& operator= (const B& b) throw(); D& operator= (const D& d) throw(); }; D& D::operator= (const B& b) throw()

segmentation fault in overloading operator =

隐身守侯 提交于 2019-12-22 12:27:19
问题 I just got a seg fault in overloading the assignment operator for a class FeatureRandomCounts, which has _rects as its pointer member pointing to an array of FeatureCount and size rhs._dim, and whose other date members are non-pointers: FeatureRandomCounts & FeatureRandomCounts::operator=(const FeatureRandomCounts &rhs) { if (_rects) delete [] _rects; *this = rhs; // segment fault _rects = new FeatureCount [rhs._dim]; for (int i = 0; i < rhs._dim; i++) { _rects[i]=rhs._rects[i]; } return

C++ Template operator overload

北城以北 提交于 2019-12-22 10:58:56
问题 I'm writing a template matrix class, and I am a bit confused as to how overloading the * operator would work. I would want to overload something like this (omitting irrelevant code): template<typename T>class Matrix4t { friend vector3 operator*(const vector3 &inputV3, const matrix4t &inputM4t); template <typename scalarT> friend scalarT operator*(const scalarT &inputSclT, const matrix4t &inputM4t); public: const matrix4t operator*(const matrix4t) vector3 operator*(const vector3 &inputV3);

Generic and (early?) binding in Swift 1.2

你说的曾经没有我的故事 提交于 2019-12-22 10:53:36
问题 func f<T>(a:T)->String { return "Generic" } func f(a:Int)->String { return "Integer" } func alias<T>(a:T)->String { return f(a) } f(1) // "Integer" f("string") // "Generic" alias(1) // "Generic" (shouldn't be "Integer" ?) alias("string") // "Generic" I understand that some form of early (static) binding is happening but I don't understand why. Is it by design or a bug? if by design then alias(a) =/= f(a) but the definition reads exactly alias(a) = f(a) ! 来源: https://stackoverflow.com

The method is ambiguous

ε祈祈猫儿з 提交于 2019-12-22 10:09:48
问题 I am trying to understand method overloading and I'm not able to understand the reason for the following code error in the following example public class OverLoading_OverRiding { public static void main(String[] args) { OverLoading_OverRiding o = new OverLoading_OverRiding(); o.sum(5, 5); } void sum(int i, long j) { } void sum(long i, int j) { } } I am getting an error: The method sum(int, long) is ambiguous for the type OverLoading_OverRiding. When i am performing explicit casting on the

Virtual function default parameters and overloading

送分小仙女□ 提交于 2019-12-22 10:09:08
问题 This question refers to common problems discussed in these questions: Can virtual functions have default parameters? Virtual functions default parameters Here is what currently happens in c++ with default parameters to virtual functions: struct Base { virtual void foo(int one = 1, int two = 2) { cout << "one: " << one << " two: " << two << endl; } }; struct Derived : public Base { virtual void foo(int one = 3, int two = 4) { Base::foo(one, two); cout << " derived!" << endl; } }; int main() {