ambiguity

Disambiguate class-member in multiple inheritance

送分小仙女□ 提交于 2019-12-17 04:35:19
问题 Suppose I have this variadic base class-template: template <typename ... Types> class Base { public: // The member foo() can only be called when its template // parameter is contained within the Types ... pack. template <typename T> typename std::enable_if<Contains<T, Types ...>::value>::type foo() { std::cout << "Base::foo()\n"; } }; The foo() member can only be called when its template-parameter matches at least one of the parameters of Base (the implementation of Contains is listed at the

Why is it ambiguous to call overloaded ambig(long) and ambig(unsigned long) with an integer literal?

扶醉桌前 提交于 2019-12-14 03:44:28
问题 When compiling void ambig( signed long) { } void ambig(unsigned long) { } int main(void) { ambig(-1); return 0; } I get error C2668: 'ambig' : ambiguous call to overloaded function could be 'void ambig(unsigned long)' or 'void ambig(long)' while trying to match the argument list '(int)' I know I can 'fix' it by saying -1L instead of -1 , but why/how exactly is this considered ambiguous in the first place? 回答1: You're passing an int to this overloaded function. Although human intuition says

Scala: ambiguous reference to overloaded definition - best disambiguation?

泄露秘密 提交于 2019-12-13 16:05:04
问题 I have a follow-on question to the problem that the presence of overloaded method definitions with and without parameters leads to a compilation error, which is already discussed here: Why is this reference ambiguous? To recap: trait A { def foo( s: String ) : String def foo : String = foo( "foo" ) } object B extends A { def foo( s: String ) : String = s } B.foo // won't compile results in the error message: error: ambiguous reference to overloaded function both method foo in object B of type

define both operator void* and operator bool

﹥>﹥吖頭↗ 提交于 2019-12-13 13:06:08
问题 I tried creating a class with one operator bool and one operator void* , but the compiler says they are ambigous. Is there some way I can explain to the compiler what operator to use or can I not have them both? class A { public: operator void*(){ cout << "operator void* is called" << endl; return 0; } operator bool(){ cout << "operator bool is called" << endl; return true; } }; int main() { A a1, a2; if (a1 == a2){ cout << "hello"; } } 回答1: You could call the operator directly. int main() {

Guidance in creating design for multiple-inheritance composite classes in c++

纵饮孤独 提交于 2019-12-13 06:02:58
问题 I intend this question to be a more generalized question relating to my question found at the following link: Solving design involving multiple inheritance and composite classes in c++ I am working with data sets related to Galaxies. The data about each galaxy will contain information about a galaxie's solar systems, each solar systems planets and each planets moons. The Composite Requirement: From this alone I imagine that I need to use composite class design where I create a class for the

Inconsistencies in compiler ambiguity errors

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 12:00:29
问题 In this question, the following class is defined: public class Program { int n = 0; public void Print() { Console.WriteLine(n); } public Program() { } public Program(int num = 10) { n = num; } } Now, obviously a call to the constructor here using new Program() is ambiguous due to the optional parameter on the second constructor. When reading this its not clear whether n should be initialized with 0 or 10 . However: Actual reporting of the problem seems inconsistent. Setting up this class and

“ambiguating new declaration” error for a templated method in a templated class

烈酒焚心 提交于 2019-12-12 01:38:47
问题 I have written the following earth-shattering application: class SomeA { }; class SomeB { }; class SomeC { }; template <typename A, typename B, typename... Cs> class Foo { public: template <typename U> static void bar(); }; template <typename U> void Foo<SomeA, SomeB, SomeC>::bar() { }; int main() { return 0; } When I compile this (gcc 4.9.3 with -std=c++11 ), I get the following error: a.cpp:10:36: error: ambiguating new declaration of ‘static void Foo<SomeA, SomeB, SomeC>::bar()’ void Foo

how to resolve simple ambiguity

廉价感情. 提交于 2019-12-11 13:50:17
问题 I just started using Antlr and am stuck. I have the below grammar and am trying to resolve the ambiguity to parse input like Field:ValueString. expression : Field ':' ValueString; Field : Letter LetterOrDigit*; ValueString : ~[:]; Letter : [a-zA-Z]; LetterOrDigit : [a-zA-Z0-9]; WS: [ \t\r\n\u000C]+ -> skip; suppose a:b is passed in to the grammar, a and b are both identified as Field. How do I resolve this in Antlr4 (C#)? 回答1: You can use a semantic predicate in your lexer rules to perform

Windows 7 Development Platform

你离开我真会死。 提交于 2019-12-11 13:25:11
问题 As some of you may have noticed, a few hours ago Microsoft released Windows 7 RTM to those of us with a Technet or MSDN subscription. I unfortunately didn't have the opportunity time-wise to test the new OS. I'm asking of anyone who used it with Visual Studio 2008 during RC what was your experience? Did you feel the RC offered a stable environment for it? Did it behave well under Windows 7? In short, can I rely on Windows 7 as my soon-to-be development platform? On another note, did anyone

How to rewrite this nondeterministic XML Schema to deterministic?

China☆狼群 提交于 2019-12-11 09:03:44
问题 Why this is non-deterministic and how to fix it? <xs:element name="activeyears"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="1"> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element ref="from" minOccurs="1" maxOccurs="1"/> <xs:element ref="till" minOccurs="1" maxOccurs="1"/> </xs:sequence> <xs:element ref="from" minOccurs="0" maxOccurs="1"/> </xs:sequence> </xs:complexType> </xs:element> It is supposed to mean that <activeyears> is either empty or contains sequence of