qualified-name

Do Derived1::Base and Derived2::Base refer to the same type?

本小妞迷上赌 提交于 2020-05-12 11:38:01
问题 MSVC, Clang and GCC disagree on this code: struct Base { int x; }; struct Der1 : public Base {}; struct Der2 : public Base {}; struct AllDer : public Der1, public Der2 { void foo() { Der1::Base::x = 5; } }; Godbolt GCC: <source>: In member function 'void AllDer::foo()': <source>:10:21: error: 'Base' is an ambiguous base of 'AllDer' 10 | Der1::Base::x = 5; | ^ Compiler returned: 1 Clang gives a similar error, and MSVC gives no error. Who is right here? I suppose this is covered in [class

How do I write the qualified name of a symbol in Haskell?

六眼飞鱼酱① 提交于 2020-01-02 00:01:18
问题 I've got a name clash between two different Haskell modules that want to use the same infix operator ( <*> ). The Haskell 98 report says that modid.varsym is permitted, but I can't get it to work. In their entirety here are Test.hs : module Test where import qualified Test2 as T three = T.<*> and Test2.hs : module Test2 where (<*>) = 3 But trying to compile results in an error message: Test.hs:6:12: parse error on input `T.<*>' I tried T.(<*>) but that doesn't work either. How can I refer to

XDocument.Descendants(itemName) - Problems finding qualified name

做~自己de王妃 提交于 2019-12-23 20:00:26
问题 I'm trying to read a XML-RSS-Feed from a website. Therefore I use a async download and create a XDocument with the XDocument.Parse() Method. The Document intends to be very simple, like this: <root> <someAttribute></SomeAttribute> <item>...</item> <item>...</item> </root> Now I want to read out all the items. Therefore I tried: foreach (XElement NewsEntry in xDocument.Descendants("item")) but this doesn't work. So I found a post in this board to use the qualified name, because there are some

Ambiguous name lookup with using-directive

眉间皱痕 提交于 2019-12-19 16:32:12
问题 It's not allowed to put a namespace and a class with the same name into one declarative region, i.e. namespace A {} class A{}; is ill-formed (see §3.3.1/4). However, one can introduce the name of either one via a using-directive: namespace N { namespace A {int i;} } struct A {static int i;}; using namespace N; int i = A::i; // The global struct, or namespace N::A? Is this code ill-formed? VC++ thinks so, as well as Clang: main.cpp:7:9: error: reference to 'A' is ambiguous int i = A::i; ^ main

Use of qualified name in function parameter

我怕爱的太早我们不能终老 提交于 2019-12-11 03:14:14
问题 According to the C++ Standard, function parameter's name is parsed by a declarator-id , and a declarator-id can also be a qualified name. That means, the following code is perfectly valid (if I've understood the relevant sections from the Standard correctly): template<class T> struct Sample { int fun(int T::count); //T::count is qualified variable name }; My question basically is, why would anyone write such code? In what situations, the use of qualified name (in function parameter-list) can

explicit qualification in C++ declaration

坚强是说给别人听的谎言 提交于 2019-12-10 13:21:40
问题 The following namespace definition fails to compile when the first declaration is commented out. If the first declaration of foo is uncommented, then it compiles just fine. namespace Y { //void foo(); void ::Y::foo(){} } The relevant part in the standard (§8.3¶1) says: When the declarator-id is qualified, the declaration shall refer to a previously declared member I understand that this rule prevents the introduction of names into other namespaces. I wonder if that rule could be relaxed to

How do I write the qualified name of a symbol in Haskell?

…衆ロ難τιáo~ 提交于 2019-12-04 22:30:59
I've got a name clash between two different Haskell modules that want to use the same infix operator ( <*> ). The Haskell 98 report says that modid.varsym is permitted, but I can't get it to work. In their entirety here are Test.hs : module Test where import qualified Test2 as T three = T.<*> and Test2.hs : module Test2 where (<*>) = 3 But trying to compile results in an error message: Test.hs:6:12: parse error on input `T.<*>' I tried T.(<*>) but that doesn't work either. How can I refer to a symbolic name defined in a module imported by import qualified ? try three = (T.<*>) It's weird to

Is it a good practice to call functions in a package via ::

杀马特。学长 韩版系。学妹 提交于 2019-11-27 17:59:29
I'm writing some R functions that employ some useful functions in other packages like stringr and base64enc . Is it good not to call library(...) or require(... ) to load these packages first but to use :: to directly refer to the function I need, like stringr::str_match(...) ? Is it a good practice in general case? Or what problem might it induce? It all depends on context. :: is primarily necessary if there are namespace collisions , functions from different packages with the same name. When I load the dplyr package, it provides a function filter , which collides with (and masks) the filter

Is it a good practice to call functions in a package via ::

我怕爱的太早我们不能终老 提交于 2019-11-26 22:38:15
问题 I'm writing some R functions that employ some useful functions in other packages like stringr and base64enc . Is it good not to call library(...) or require(... ) to load these packages first but to use :: to directly refer to the function I need, like stringr::str_match(...) ? Is it a good practice in general case? Or what problem might it induce? 回答1: It all depends on context. :: is primarily necessary if there are namespace collisions , functions from different packages with the same name

Why isn't a qualified static final variable allowed in a static initialization block?

天大地大妈咪最大 提交于 2019-11-26 16:13:29
Case 1 class Program { static final int var; static { Program.var = 8; // Compilation error } public static void main(String[] args) { int i; i = Program.var; System.out.println(Program.var); } } Case 2 class Program { static final int var; static { var = 8; //OK } public static void main(String[] args) { System.out.println(Program.var); } } Why does Case 1 cause a compilation error? The JLS holds the answer (note the bold statement): Similarly, every blank final variable must be assigned at most once; it must be definitely unassigned when an assignment to it occurs. Such an assignment is