Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

Does C++ support same names for a class and its data member?? I know it does cos i compiled n ran this without error on codeblocks, OS windows7... #include using namespace std; class abc { public: int abc; char bc; }; int main() { abc abc; abc.abc=1,abc.bc='3'; cout<

OpenStudy (anonymous):

this is not a 'new' feature, and not only C++ does this. To prove it to you I will write a similar code in java: //test.java class SampleClass { public int SampleClass = 300; } public class test { public static void main(String[] args) { SampleClass myClass = new SampleClass(); System.out.println(myClass.SampleClass); } } Anyways, it's definitely not recommended otherwise your code will be really confusing.

OpenStudy (anonymous):

Windows 7, written in geany IDE

OpenStudy (anonymous):

thanks bt I'm still confused cuz it was reported as an error on XP....

OpenStudy (anonymous):

what kind of error?

OpenStudy (anonymous):

has d OS gt antg to do with this??

OpenStudy (anonymous):

it said the names of class n its member can't b same...even my lecturer said it can;t be

OpenStudy (anonymous):

it wouldn't make any sense if the OS is the problem. But either way it doesn't seem to be worth finding out. 99.9% you wouldn't use name of class for its members because that is reserved for the constructor.

OpenStudy (anonymous):

its kinda worth cuz twas askd in test n nw she's arguing tht they cant b same

OpenStudy (anonymous):

it was asked in a test?? Lol. Show and run the code for her to see then. It should possible in most languages, just not practical.

OpenStudy (anonymous):

I don't see how she could argue with this... the output wins. The code works

OpenStudy (anonymous):

did that too...God i hate conservative ppl, blaming it on d OS!

OpenStudy (anonymous):

She like, living in denial or smth? I'd say don't hurt her ego and let her win. Put your thinking to something more productive

OpenStudy (anonymous):

anyway thanks :) i jus wanna know y its an error on XP n nt on 7

OpenStudy (anonymous):

It shouldn't be the operating system. If anything, it's the compiler.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!