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
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.
Windows 7, written in geany IDE
thanks bt I'm still confused cuz it was reported as an error on XP....
what kind of error?
has d OS gt antg to do with this??
it said the names of class n its member can't b same...even my lecturer said it can;t be
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.
its kinda worth cuz twas askd in test n nw she's arguing tht they cant b same
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.
I don't see how she could argue with this... the output wins. The code works
did that too...God i hate conservative ppl, blaming it on d OS!
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
anyway thanks :) i jus wanna know y its an error on XP n nt on 7
It shouldn't be the operating system. If anything, it's the compiler.
Join our real-time social learning platform and learn together with your friends!