Buckys C++ Programming Tutorials - 13 - Using Variables in Classes

+2 Lovya Vinayak · July 9, 2014
In the tutorial is 

private string name;

 an instance field?

Post a Reply

Replies

Oldest  Newest  Rating
+1 Tamdio Foranz · July 22, 2014
Don't know if this is what you want but here is an example of member variables in C++ using good practice.

class MyEpicClass{
public:
//Every body has access to these members and methods
std::string getName(){return theName;}
private:
//Only this class has access to these members and methods
std::string theName = "Bob"; //C++11 Only style initialization
protected:
//Only this class and classes that inherit from it have access to these members and methods
}


DO NOT EVER USE GLOBAL VARIABLES IN C++ EVER x 90000 ^ 999999 NEVER.

If you need access to a method from a class WITHOUT creating an instance of it we use a static method.
  • 1

C++

106,940 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator