Wednesday, July 8, 2020
Scope Resolution Operator In C++
Scope Resolution Operator In C++ How To Best Utilize Scope Resolution Operator In C++? Back Home Categories Online Courses Mock Interviews Webinars NEW Community Write for Us Categories Artificial Intelligence AI vs Machine Learning vs Deep LearningMachine Learning AlgorithmsArtificial Intelligence TutorialWhat is Deep LearningDeep Learning TutorialInstall TensorFlowDeep Learning with PythonBackpropagationTensorFlow TutorialConvolutional Neural Network TutorialVIEW ALL BI and Visualization What is TableauTableau TutorialTableau Interview QuestionsWhat is InformaticaInformatica Interview QuestionsPower BI TutorialPower BI Interview QuestionsOLTP vs OLAPQlikView TutorialAdvanced Excel Formulas TutorialVIEW ALL Big Data What is HadoopHadoop ArchitectureHadoop TutorialHadoop Interview QuestionsHadoop EcosystemData Science vs Big Data vs Data AnalyticsWhat is Big DataMapReduce TutorialPig TutorialSpark TutorialSpark Interview QuestionsBig Data TutorialHive TutorialVIEW ALL Blockchain Blockchain TutorialWhat is BlockchainHyperledger FabricWhat Is EthereumEthereum TutorialB lockchain ApplicationsSolidity TutorialBlockchain ProgrammingHow Blockchain WorksVIEW ALL Cloud Computing What is AWSAWS TutorialAWS CertificationAzure Interview QuestionsAzure TutorialWhat Is Cloud ComputingWhat Is SalesforceIoT TutorialSalesforce TutorialSalesforce Interview QuestionsVIEW ALL Cyber Security Cloud SecurityWhat is CryptographyNmap TutorialSQL Injection AttacksHow To Install Kali LinuxHow to become an Ethical Hacker?Footprinting in Ethical HackingNetwork Scanning for Ethical HackingARP SpoofingApplication SecurityVIEW ALL Data Science Python Pandas TutorialWhat is Machine LearningMachine Learning TutorialMachine Learning ProjectsMachine Learning Interview QuestionsWhat Is Data ScienceSAS TutorialR TutorialData Science ProjectsHow to become a data scientistData Science Interview QuestionsData Scientist SalaryVIEW ALL Data Warehousing and ETL What is Data WarehouseDimension Table in Data WarehousingData Warehousing Interview QuestionsData warehouse architectureTalend T utorialTalend ETL ToolTalend Interview QuestionsFact Table and its TypesInformatica TransformationsInformatica TutorialVIEW ALL Databases What is MySQLMySQL Data TypesSQL JoinsSQL Data TypesWhat is MongoDBMongoDB Interview QuestionsMySQL TutorialSQL Interview QuestionsSQL CommandsMySQL Interview QuestionsVIEW ALL DevOps What is DevOpsDevOps vs AgileDevOps ToolsDevOps TutorialHow To Become A DevOps EngineerDevOps Interview QuestionsWhat Is DockerDocker TutorialDocker Interview QuestionsWhat Is ChefWhat Is KubernetesKubernetes TutorialVIEW ALL Front End Web Development What is JavaScript â" All You Need To Know About JavaScriptJavaScript TutorialJavaScript Interview QuestionsJavaScript FrameworksAngular TutorialAngular Interview QuestionsWhat is REST API?React TutorialReact vs AngularjQuery TutorialNode TutorialReact Interview QuestionsVIEW ALL Mobile Development Android TutorialAndroid Interview QuestionsAndroid ArchitectureAndroid SQLite DatabaseProgramming aria-current=page>Uncat egorizedHow To Best Utilize Scope Reso... AWS Global Infrastructure C++ Programming Tutorial: The key you need to Master C++ What are the top 10 features of C++? Everything You Need To Know About Object Oriented Programming In C++ How To Work With File handling in C++? How To Implement Data Abstraction In C++ How To Implement Copy Constructor In C++? Data Hiding in C++: What is Encapsulation and Abstraction? How To Implement Constructor And Destructor In C++? What is a Storage Class in C++ and its types? How To Display Fibonacci Series In C++? How To Implement Pointers In C++? How To Implement This Pointer in C++? How To Implement Arrays In C++? How To Convert Integer To String In C++? How To Calculate String Length In C++? How To Convert Integer To String In C++? How To Implement Operator Overloading in c++? How To Implement Function Overloading And Overriding In C++? What are Maps in C++ and how to implement it? How To Implement Encapsulation In C++? How To Implement Exception Handling In C++? Goto Statement In C++ How To Implement Getline In C++? How To Implement Goto Statement In C++? How To Implement Sort function In C++? How To Implement Virtual Function in C++? How To Implement Inline Function in C++? How To Best Implement Type Conversion In C++? How To Best Utilize Scope Resolution Operator In C++? Published on Sep 10,2019 4.4K Views edureka Bookmark As the name suggests, Scope resolution operator is used to get the hidden names due to variable scopes so that you can still use them. In this article we will understand how to use scope resolution operator in C++ what are its different purposes from a programming perspective.In C++, scope resolution operator is ::. Scope resolution operator in C++ can be used for:Accessing a global variable when there is a local variable with same nameDefining a function outside a classAccessing a classs static variablesReferring to a class inside another classI n case of multiple InheritanceNamespaceNow lets understand each of the purpose one by one with the help of examples.Accessing a global variable when there is a local variable with same nameYou can use scope resolution operator to access the global variable if you have a local variable with the same name. In the below example we have two variables both name num with global local scope. So, to access the global num variable in the main class you need to use scope resolution operator (i.e. ::num).Example #includeiostream using namespace std; int num = 30; // Initializing a global variable num int main() { int num = 10; // Initializing the local variable num cout Value of global num is ::num; cout nValue of local num is num; return 0; } OutputMoving on with this article on Scope Resolution Operator In C++Defining a Function Outside a ClassIf you are declaring a function in a class and then later want to define it outside the class, you can do that using scope resolution operator. In the below example, we are declaring a function Speed in Class Bike. Later we are defining the function in the main class using scope resolution operator.Example #includeiostream using namespace std; class Bike { public: // Just the Function Declaration void Speed(); }; // Defining the Speed function outside Bike class using :: void Bike::Speed() { cout Speed of Bike is 90 KMPH; } int main() { Bike bike; bike.Speed(); return 0; } OutputMoving on with this article on Scope Resolution Operator In C++Accessing a classs static variablesYou can access the classs static variable using class name scope resolution operator (i.e. class_name::static_variable). You can see in the below example, we are declaring a static variable in the class. We are defining the variable outside the class using the scope resolution operator. Then we are accessing it using class name scope resolution operator.Example #includeiostream using namespace std; class Try { static int num1; public: static int num2; // Local parameter hides class member // Class member can be accessed it using :: void function(int num1) { // num1 static variable can be accessed using :: // inspite of local variable num1 cout Static num1: Try::num1; cout nLocal num1: num1; } }; // Defining a static members explicitly using :: int Try::num1 = 10; int Try::num2 = 15; int main() { Try o; int num1 = 20 ; o.function(num1); cout nTry::num2 = Try::num2; return 0; } OutputMoving on with this article on Scope Resolution Operator In C++Referring to a class inside another classYou can create nested class with same variable names in both the classes. You can access both the variables using scope resolution operator. For the inner class variable, you need to use Outer_Class::Inner_Class::variable. Example #includeiostream using namespace std; class Outside_class { public: int num; class Inside_class { public: int num; static int x; }; }; int Outside_class::Inside_class::x = 5; int main(){ Outside_class A; Outside_class::Inside_class B; } Moving on with this article on Scope Resolution Operator In C++In case of multiple InheritanceIf you have two parent classes with same variable names and you are inheriting both of them in the child class, then you can use scope resolution operator with the class name to access the individual variables.In the below example, we are creating two parent class Parent1 Parent2, and both of them have variable num. When we are inheriting both of them in Child class, we can access both the num variables using class name scope resolution operator.Example #includeiostream using namespace std; class Parent1 { protected: int num; public: Parent1() { num = 100; } }; class Parent2 { protected: int num; public: Parent2() { num = 200; } }; class Child: public Parent1, public Parent2 { public: void function() { cout Parent1's num is Parent1::num; cout nParent2's num is Parent2::num; } }; int main() { Child obj; obj.function(); return 0; } OutputMoving on with this article on Scope Resolution Operator In C++NamespaceSuppose we have two namespaces both contains class with same name. So to avoid any conflict we can use namespace name with the scope resolution operator. In the below example we are using std::cout.Example #includeiostream int main(){ std::cout Hello std::endl; } OutputNow after going through the above programs you would have understood everything about scope resolution operator in C++. I hope this blog is informative and added value to you.Now after executing the above program you would have understood the Scope Resolution Operator In C++. Thus we have come to an end of this article on Quicksort in Java. If you wish to learn more, check out the Java Training by Edureka, a trusted online learning company. Edurekas Java J2EE and SOA training and certification course is designed to train you for both core and advanced Java concepts along with various Java frameworks like Hibernate Spring.Got a question for us? Please mention it in the comments section of this blog and we will get back to you as soon as possible.Recommended blogs for you Your Guide to the Top 10 IT Certifications for 2020 Read Article How do you make a Career in Software Testing? Read Article How to Choose the Right Postgraduate Program for You? Read Article What are the top 10 features of C++? Read Article Software Testing Life Cycle- Different Stages of Testing Read Article Infographic A Beginners Guide to the Indian IT Ecosystem Read Article Top 5 Cryptocurrencies To Look Out For In 2019 Read Article Vol. III â" Edureka Career Watch â" 26th Jan. 2019 Read Article What is Network Security: An introduction to Network Security Read Article 7 Habits of Highly Effective DevOps Read Article SAFe Agile Certification Exam Requirements: Everything You Need to Know Read Article A Beginnerâs Guide To CRM Salesforce Read Article A Step-by-Step Guide On Automation Anywhere Installation Read Article NDTV Interview with Edurekaâs Customers Team about its Learning Methodology Read Article What are the Types of Software Testing Models? Read Article Big Data Engineer Salary How Much Can You Expect As A Big Data Engineer? Read Article Apache Cassandra Advantages Read Article What is Software Testing Metrics and What are the Types? Read Article A Step by Step Gu ide on How to Install JMeter Read Article What are 26 ITIL ® Processes and how they work? Read Article Comments 0 Comments Trending Courses Python Certification Training for Data Scienc ...66k Enrolled LearnersWeekend/WeekdayLive Class Reviews 5 (26200)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.