Jump to content

Hey guys, I had a quick question about classes in c++ that I cannot think of the logical answer for

My question is what happens if a member function has a local variable that is the same name as

a data member? Which one would take precedence? Also what functions can modify private data

members in a class?

i5 4670k| Asrock H81M-ITX| EVGA Nex 650g| WD Black 500Gb| H100 with SP120s| ASUS Matrix 7970 Platinum (just sold)| Patriot Venom 1600Mhz 8Gb| Bitfenix Prodigy. Build log in progress 

Build Log here: http://linustechtips.com/main/topic/119926-yin-yang-prodigy-update-2-26-14/

Link to comment
https://linustechtips.com/topic/546123-c-classes-question/
Share on other sites

Link to post
Share on other sites

Quote

 

My question is what happens if a member function has a local variable that is the same name as

a data member?

 

 

Local scope comes first, then class scope. The function variable comes first. General good practice is to add a _ at the end of class variables.

Quote

Also what functions can modify private data

members in a class?

 

Member and friend functions of the class

 

 

Link to comment
https://linustechtips.com/topic/546123-c-classes-question/#findComment-7221487
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×