using-declaration

The difference between declaring a name, introducing a name, and declaring an entity

吃可爱长大的小学妹 提交于 2021-02-18 22:30:28
问题 From the C++11 standard, §7.3.3[namespace.udecl]/1: A using-declaration introduces a name into the declarative region in which the using-declaration appears. using-declaration : using typename opt nested-name-specifier unqualified-id ; using :: unqualified-id ; The member name specified in a using-declaration is declared in the declarative region in which the using-declaration appears. What do they mean by the name being declared in the declarative region where the using-declaration occurs?

Can you use using to redeclare a public member in base class as private in derived class?

不问归期 提交于 2020-06-16 03:37:08
问题 This code snippet demonstrating changing class member access came from IBM. struct A { protected: int y; public: int z; }; struct B : private A { }; struct C : private A { public: using A::y; using A::z; }; struct D : private A { protected: using A::y; using A::z; }; struct E : D { void f() { y = 1; z = 2; } }; struct F : A { public: using A::y; private: using A::z; }; int main() { B obj_B; // obj_B.y = 3; // obj_B.z = 4; C obj_C; obj_C.y = 5; obj_C.z = 6; D obj_D; // obj_D.y = 7; // obj_D.z

Variadic base class using declaration fails to compile in MSVC

夙愿已清 提交于 2020-02-04 20:57:19
问题 I'm trying to implement a variadic visitor class. template<typename T> class VisitorBaseFor { protected: virtual ~VisitorBaseFor() = default; public: virtual void visit(T &t) = 0; }; template<typename... Ts> class VisitorBase : public VisitorBaseFor<Ts>... { public: using VisitorBaseFor<Ts>::visit...; }; I know from that overload trick that variadic using declarations should be possible, but MSVC does not compile my code saying I need to expand Ts while both GCC and Clang compile my code

How to make all hidden names from a base class accessible in derived one?

随声附和 提交于 2020-01-22 20:39:49
问题 Starting from this question: Pointer derived from pure virtual class(A) can't access overload method from the pure class (B) And considering this simplified code: #include <string> #include <iostream> class Abstract { public: virtual void method(int a) { std::cout << __PRETTY_FUNCTION__ << "a: " << a << std::endl; } }; class Concrete : public Abstract { public: void method(char c, std::string s) { std::cout << __PRETTY_FUNCTION__ << "c: " << c << "; s: " << s << std::endl; } }; int main() {

How to make all hidden names from a base class accessible in derived one?

不打扰是莪最后的温柔 提交于 2020-01-22 20:39:33
问题 Starting from this question: Pointer derived from pure virtual class(A) can't access overload method from the pure class (B) And considering this simplified code: #include <string> #include <iostream> class Abstract { public: virtual void method(int a) { std::cout << __PRETTY_FUNCTION__ << "a: " << a << std::endl; } }; class Concrete : public Abstract { public: void method(char c, std::string s) { std::cout << __PRETTY_FUNCTION__ << "c: " << c << "; s: " << s << std::endl; } }; int main() {

A using-declaration can not be repeated in function scope. Why is that?

℡╲_俬逩灬. 提交于 2019-12-31 19:26:30
问题 In [namespace.udecl]/10 you have the following example: namespace A { int i; } namespace A1 { using A::i; using A::i; // OK: double declaration } void f() { using A::i; using A::i; // error: double declaration } This snippet compiles in clang. 回答1: The first is a declaration inside a namespace, and the multiple using statements could happen frequently using #includes. The second is inside a definition of a function, and you would never do that unless you made a mistake. You can't define the