I'm not sure how to phrase this or what it's actually called, but I know that in Objective-C you can have multiple constructors that can successively call one another, forgive any code erros, I haven't done this in a while, but the idea is there.
- (id)initWithTitle:(NSString *)_title;
- (id)initWithTitle:(NSString *)_title page:(NSString *)_page;
-----------------------------------
- (id)initWithTitle:(NSString *)_title {
return [self initWithTitle:_title page:nil];
}
- (id)initWithTitle:(NSString *)_title page:(NSString *)_page {
if(self = [super init]) {
self.title = _title;
self.page = _page;
}
return self;
}
I'm just wondering if there is an equivalent of this in c++;
Prior to C++11 you couldn't do this, but as of C++11 you can
class Foo {
int d;
public:
Foo (int i) : d(i) {}
Foo () : Foo(42) {} //new to c++11
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With