0

my_func.h

class MyClass{
 public:
  OtherClass otherclass;
  void func();
  void func(OtherClass others);
};

my_func.cpp

#includ <my_func.h>

void MyClass::func(){
 func(this->otherclass);
}

void MyClass::func(OtherClass others){
 if(others.value.IsObject)
   func(others.value);
}

main.cpp

#include <my_func.h>

int main(){
 func();
}

I want to refactoring this code.

I want to set default parameter, so I write code like this.

but I think there is a better way.

3
  • 1
    Your implementations of func are introducing new non-class functions. In order to implement the class methods use e.g. void MyClass::func(){ ... }. Commented Nov 8, 2022 at 8:29
  • 1
    As is, your function seems to do nothing observable... Commented Nov 8, 2022 at 8:31
  • I modify code refer to your comment. I dont want to use override like this. I want to set default parameter like void func(Otherclass others=this->otherclass) Commented Nov 8, 2022 at 8:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.