fork download
  1. namespace Test
  2. {
  3.  
  4. class cTest
  5. {
  6. public:
  7. float Temp;
  8. };
  9.  
  10. class cTest2
  11. {
  12. public:
  13. cTest Calculate()
  14. {
  15. cTest TempTest;
  16. return TempTest;
  17. };
  18. };
  19.  
  20. //This class is implemented to show that it's not the namespace location that causes the compile error to occur.
  21. //Used only in Method 2
  22. class cTest3
  23. {
  24. public:
  25.  
  26. cTest2 TempTest2_Obj;
  27. int ReturnValue;
  28.  
  29. int TestFunction()
  30. {
  31. ReturnValue = TempTest2_Obj.Calculate(); //The compiler looks up the object and finds an entry for Calculate,
  32. //and settles on the 'v' (Or void/no arguments) entry, but somehow it knows
  33. //its return type is of cTest, without name decoration!
  34. return ReturnValue;
  35. };
  36. };
  37. };
  38.  
  39. int main()
  40. {
  41. //Method 1 of demonstrating the function selection problem.
  42. /** /
  43.   Test::cTest2 TempObj1;
  44.   Test::cTest2 TempObj2;
  45.  
  46.   TempObj1 = TempObj2.Calculate();
  47. /**/
  48.  
  49. //Method 2 of demonstrating the function selection problem.
  50. /**/
  51. Test::cTest3 TempObj3;
  52. TempObj3.TestFunction();
  53. /**/
  54.  
  55. return 0;
  56. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:47:1: warning: "/*" within comment
prog.cpp: In member function ‘int Test::cTest3::TestFunction()’:
prog.cpp:31: error: cannot convert ‘Test::cTest’ to ‘int’ in assignment
stdout
Standard output is empty