Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does C++ using mean inside a class?

What does it mean to have a using inside a class definition?

class myClass {
public:
  [...]
  using anotherClass::method;
};
like image 990
WilliamKF Avatar asked Mar 05 '11 16:03

WilliamKF


People also ask

What does using mean in C++?

​The using keyword is used to: Bring a specific member from the namespace into the current scope. Bring all members from the namespace into​ the current scope. Bring a base class method ​or variable into the current class's scope.

What is the use of class in C?

Master C and Embedded C Programming- Learn as you go A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.

Can we write class inside main in C++?

How can we write main as a class in C++? As it is already known that main() method is the entry point in any program in C++, hence creating a class named “main” is a challenge and is generally not possible.


1 Answers

That declaration unhides a base class member. This is most often used to allow overloads of a member function. Example:

class Base {
public:
   void method() const;
};

class Derived : public Base {
public:
   void method(int n) const;
   // Without the using, you would get compile errors on d.method();
   using Base::method;
};
like image 172
aschepler Avatar answered Sep 18 '22 13:09

aschepler