answersLogoWhite

0


Best Answer

Private variables can only be accessed from outside of a class by using any public function of that same class. Or this can be accomplished by using Friend functions.

User Avatar

Wiki User

18y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is it possible to access the private variable in CPP from outside the class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What specifies private access modifier and private base class?

A private variable is something that is not visible outside the class. A private class is one that cannot be inherited


What is the difference between a global variable and a private variable?

The accessibility. The global one: almost everywhere in the code may reference to the global variable directly. The private variable, is private to the declaring module (class, method, assembly) only. Outside of that module has no access to it directly.


What is the purpose of public in java programming?

Public, Protected, and Private specify what has access to a routine or variable. Public is the most generous, meaning that variable or routine can be accessed from both inside and outside that program. Protected means that the variable or routine can be accessed broadly within the program, but not from outside. private means that variable or routine is only accessible to routine it is part of.


How do you access private variable in flex?

In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }


What is a default access specifier for variable in c sharp?

Default access specifier in c# is private. if you don't specify it automaticaly takes it as private.


Which is public to all access class or struct or function or variable?

The default access specifier for a class is private. The default access specifier for a struct is public. It does not matter if it is a function or a variable.


What is meant by private visibilty of a method?

It means that the method is visible from only within the current method. Also, any class that wants to use or invoke the private method has to create an object of the class in which the method is created in order to access/invoke it. The private access modifier is the most restrictive of the four java access modifiers. The total opposite of private is public which gives access to everyone.


What kinds of access can a class member have?

Public, protected and private access members.


What is Get Setting in programming language?

Data value (hold in a variable) in a program can be made safe by declaring it as private and public Getter and setter method can be written to access the same. So Getter/setter are the interface to outside world.


What does it mean by encapsulation?

Encapsulation makes class fields private, preventing access to it from outside of the class. Essentially, this data is hidden from the rest of the program. It is possible to allow access to the fields via public methods.


Java Which access modifier is preferred for instance variables?

Usually Private is the preferred access modifier for instance variables. Benefits: 1. No other class can access this variable directly. They can do only through the getter/setter methods 2. Only the methods in that particular class can use this variable


Which is the keyword used to access the variable declared as global variable in another file?

To be able to access a variable declared in one file/class from another file/class you need to declare that variable as "public". Doing this is a very bad coding practice because exposing a variable of a class to be available publicly to other classes is totally against the Java object oriented concepts of Encapsulation and Data hiding. So, preferably you shouldn't be doing this. However, a better way to do this is, declare the variable as private and have public accessor methods through which you can access this variable. This will ensure that your data is protected even if it is available outside the class