I'm learning various details of OOP in C++ and wrote that code. The purpose of that code is to toy with ctor-initializers and learn how to inirialize a reference that is a class attribute.
#include <string>
#include <iostream>
using namespace std;
class Corgi {
private:
const string nickname;
const string& rNickname;
public:
Corgi(const string& _nickname): nickname(nickname), rNickname(nickname) {}
};
int main() {
Corgi buddy("buddy");
return 0;
}
This code compiles, however, I get this error message when it runs:
Project(1343,0x7fff7b2f2000) malloc: *** mach_vm_map(size=140734714511360) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
I don't understand why I get this error message and how I can fix that. So, why do I get it and how to fix that?
I appreciate any help.