0
class A{
private:
    int num{0};
public:
    void func1(A obj){
        std::cout<<obj.num;
    }
    void func2(){
        // func1(/*pass current obj by value here*/);
    }
};

how do I pass the current object being worked to func1 by value from within the same class?

  • 1
    If you mean passing the object that `this` points to, you get access to it like for any other pointer: You *dereference* it, as in `*this`. – Some programmer dude Jul 19 '21 at 06:54
  • A small design-question: Why is `func1` a normal (and not a `static`) member function? What is its purpose? What problem is it supposed to solve? And why does it take its argument by value rather than by (`const`) reference? – Some programmer dude Jul 19 '21 at 06:56
  • @Someprogrammerdude overconfidently i chose to make a chess engine(just good enough to work) for my oop project and i need to pass the chessboard object by value through the minimax function so previous states wont be changed. there are other alternatives but this way is easier. – notri-hairy Jul 19 '21 at 08:10
  • Well you can still pass by (const) reference, as then the object won't need to be copied each call. – Some programmer dude Jul 19 '21 at 08:13

0 Answers0