fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. class A{
  7. char m_byteValue;
  8. public:
  9. A(unsigned char c) {
  10. m_byteValue = c;
  11. }
  12. };
  13.  
  14.  
  15. class B{
  16. int m_a;
  17. public:
  18. B(){
  19. m_a = 2;
  20. }
  21. int Set(B *);
  22. int Set(const A&);
  23. };
  24.  
  25. int B::Set(const A& v) {
  26. cout << "I am in the const ref function\n";
  27. return 0;
  28. }
  29.  
  30. int B::Set(B* p) {
  31. cout << "I am in the pointer function\n";
  32. return 0;
  33. }
  34.  
  35. int main(){
  36. const unsigned char a = 0;
  37. const unsigned char b = 1;
  38. unsigned char c = 0;
  39. unsigned char d = 1;
  40. B var;
  41. var.Set(a);
  42. var.Set(b);
  43. var.Set(c);
  44. var.Set(d);
  45. return 0;
  46. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
I am in the pointer function
I am in the const ref function
I am in the const ref function
I am in the const ref function