0

Can I set an variable to a value in my class, and declare it in int main?

I created a program that used a class that had you set a variable to a certain value. Then in in int main I declared these variables. And then I called the function in main after I had declared the variables. But I got an error saying I didn't declare the variable despite the fact that I declared the variable in main before accessing it from my class.

23rd Jun 2019, 1:15 PM
Mythical Coding
Mythical Coding - avatar
3 ответов
0
You can't access the variables of a function from another function , you need to return the value and assign it in main.
23rd Jun 2019, 1:27 PM
tiberiu
tiberiu - avatar
0
No you can't access it directly but if you have a global variable then you can do something take look at my code: https://code.sololearn.com/c7bcCU4qa7Qw/?ref=app
23rd Jun 2019, 4:22 PM
Sahil Bhakat
Sahil Bhakat - avatar
0
You have to know the basics of the pointer to understand it!
23rd Jun 2019, 4:23 PM
Sahil Bhakat
Sahil Bhakat - avatar