I am trying a program with friend function(max) which is common to 2 classes(XYZ and ABC). Here though compilation doesn't show any error/warning, I can't see expected output on console. So I tried to display something just to see if it comes on screen. But strange enough, nothing comes up on the screen.
Can you please have a look at the code below? Am I missing something? (specially to include any required header file)
I am using g++ compiler on a GNU/Linux and don't have a debugger... :(
Just using crimson editor.
And yes, I am not getting Test1, Test2 or Test3 on screen
How do you run this program? Afaik, this program will not do anything by itself - it won't start terminal; you have to either use it from terminal, or have some IDE provide you with their terminal for program to work.
A shot in the dark: You are naming the program "test" when you build it. Unix/Linux already have a program named test, so you are running that program and not yours. Try giving the absolute path: $ ./test
Pro tip: If you aren't seeing "Test2" or "Test3" on console, you need to try this:
@MatthewRock: I am compiling and running it from bash shell prompt like below
Compile:
-bash-3.00$ g++ Friend_Function_2Classes.cpp -o Friend_Function_2Classes
@LowestOne: It worked. I added void in int main() as suggested by you and it showed output. Also to add, now when I remove void again from int main() and recompile and run it, it still shows output :-)
Can you please explain the reason behind this behavior?
Linux is kindof funky. I was using std::cout in constructors and it showed the output on Windows, but not on Linux. I don't think it is related, but Linux is a bit weird sometimes.
Thank you all for your informative and wonderful replies.
@TheIdeasMan: I'll try to explore more gcc options and will make use of manual also. Thanks for the suggestion. :-)