I tried out a c++ program, where i declared a variable of type int named "a" inside a class. And created a function named "b" inside which again i declared a variable named "a" and assigned the value to it. The variable "a" inside the function is considered as local variable. And if i want to assign the value to the variable a which is present in the class definition(not inside the function), how can i do it?
#include <iostream>
using namespace std;
class a{
public:int a;//need to assign value for this "a" inside the function how can i do it
int b(){
int a=5;
a=7;
cout<<a;
}
};
int main() {
a A;
A.b();
}
int & ra = a;before you decareain the function. Then userato refre to the class scopea.ain a class nameda, can you?