ambiguity

Solving design involving multiple inheritance and composite classes in c++

半腔热情 提交于 2019-12-03 07:19:05
I have struggled with this design problem for some time. I will do my best to explain what I am trying to do and the various approached that I have seen, what I am trying and why. I work in a scientific computing environment where I deal with the same kinds of objects repeatedly. Imagine a galaxy which contains solar systems, each solar system contains planetary systems and each planetary system contains moons. To this end I think of the situation as a “has a” situation, and thus I have used composition to give the galaxy access to its solar systems, and each solar system access to the

C++ method call and type scope resolution ambiguity

感情迁移 提交于 2019-12-03 05:53:53
I hope the title actually describes what I wanted to ask... I wrote a piece of code that compiles with gcc and works as I intended. However, it does not compile with llvm and the code executes differently when compiled with icc! Here is an example of the problem: #include <iostream> using std::cout; using std::endl; class A { public: virtual void foo() { cout << "A::foo()" << endl; } }; class B : public A { public: typedef A base; virtual void foo() { cout << "B::foo()" << endl; } }; int main() { typedef B base; base* bp = new B(); bp->base::foo(); } gcc output: A::foo() icc output: B::foo()

No warning or error (or runtime failure) when contravariance leads to ambiguity

落花浮王杯 提交于 2019-12-03 01:38:05
问题 First, remember that a .NET String is both IConvertible and ICloneable . Now, consider the following quite simple code: //contravariance "in" interface ICanEat<in T> where T : class { void Eat(T food); } class HungryWolf : ICanEat<ICloneable>, ICanEat<IConvertible> { public void Eat(IConvertible convertibleFood) { Console.WriteLine("This wolf ate your CONVERTIBLE object!"); } public void Eat(ICloneable cloneableFood) { Console.WriteLine("This wolf ate your CLONEABLE object!"); } } Then try

C# The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)

泪湿孤枕 提交于 2019-12-03 01:00:08
My code won't compile due to the error below: The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int) My code is Math.Round(new FileInfo(strFilePath).Length / 1024, 1) How can I fix this? Thanks Lucero The problem is that you make an integer division (results also in an int ) and a int can be implicitly converted to both double and decimal . Therefore, you need to make sure the expression results in one of those; double is probably what you want. Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1) Math.Round

No warning or error (or runtime failure) when contravariance leads to ambiguity

落爺英雄遲暮 提交于 2019-12-02 16:53:11
First, remember that a .NET String is both IConvertible and ICloneable . Now, consider the following quite simple code: //contravariance "in" interface ICanEat<in T> where T : class { void Eat(T food); } class HungryWolf : ICanEat<ICloneable>, ICanEat<IConvertible> { public void Eat(IConvertible convertibleFood) { Console.WriteLine("This wolf ate your CONVERTIBLE object!"); } public void Eat(ICloneable cloneableFood) { Console.WriteLine("This wolf ate your CLONEABLE object!"); } } Then try the following (inside some method): ICanEat<string> wolf = new HungryWolf(); wolf.Eat("sheep"); When one

Can I avoid an ambiguity, when I declare a fixed length vector in class?

三世轮回 提交于 2019-12-02 10:39:56
问题 I want to declare a vector of 2 elements as a class member. But next code generates an error: class A { private: std::vector<int> v (2); ... } The compiler curses about "2" is constant. As I understand, the problem is, the ambiguity arises, because the compiler parses the string of vector declaration as an function declaration (function, that takes "2" as an argument and returns vector of ints). Question: Can I avoid this ambiguity? How can I do this? PS: outside the class this vector

Can I avoid an ambiguity, when I declare a fixed length vector in class?

杀马特。学长 韩版系。学妹 提交于 2019-12-02 04:13:33
I want to declare a vector of 2 elements as a class member. But next code generates an error: class A { private: std::vector<int> v (2); ... } The compiler curses about "2" is constant. As I understand, the problem is, the ambiguity arises, because the compiler parses the string of vector declaration as an function declaration (function, that takes "2" as an argument and returns vector of ints). Question: Can I avoid this ambiguity? How can I do this? PS: outside the class this vector declaration is parsed correctly. An in-class initialiser has to use braces or the equals sign; so this could

Content model ambiguity in a schema

拜拜、爱过 提交于 2019-12-02 02:10:33
Maybe I've been staring at this problem for too long, maybe there isn't an answer; either way I'm here now. I'm trying to permit a set of possible combinations in an XSD, but I can't seem to find an approach that doesn't result in ambiguity. Quick regexy respresentation: foo+ ( bar baz* | bar? baz+ qux* ) foo is required ( one-or-more ) If bar exists, baz is optional ( zero-or-more ) If baz exists, bar is optional ( zero-or-one ) and qux is optional ( zero-or-more ) qux can not exist if baz does not exist Ambiguity arises given foo bar baz . Ambiguous XSD document: <xs:element name="parent">

Overload Resolution/Ambiguity in name lookup(which one)

冷暖自知 提交于 2019-12-01 19:50:55
$7.3.3/14 (C++03) struct A { int x(); }; struct B : A { }; struct C : A { using A::x; int x(int); }; struct D : B, C { using C::x; int x(double); }; int f(D* d) { return d->x(); // ambiguous: B::x or C::x } The comment in the code in 'f' indicates that one can expect ambiguity between 'B::x' or 'C::x'. However, on compiling with g++(ideone) or Comeau the errors are slightly different. These errors instead of indicating ambiguity in B::x or C::x indicate the fact that A is an ambiguous base of D prog.cpp: In function ‘int f(D*)’: prog.cpp:16: error: ‘A’ is an ambiguous base of ‘D’ And

Problems with an ambiguous grammar and PEG.js (no examples found)

回眸只為那壹抹淺笑 提交于 2019-12-01 17:47:45
I want to parse a file with lines of the following content: simple word abbr -8. (012) word, simple phrase, one another phrase - (simply dummy text of the printing; Lorem Ipsum : "Lorem" - has been the industry's standard dummy text, ever since the 1500s!; "It is a long established!"; "Sometimes by accident, sometimes on purpose (injected humour and the like)"; "sometimes on purpose") This is the end of the line so now explaining the parts (not all spaces are described, because of the markup here): simple word is one or several words (phrase) separated by the whitespace abbr - is a fixed part