This question already has an answer here:
- make_unique and perfect forwarding 7 answers
I'm trying to get some practice with smart pointers (specifically unique_ptr), but my compiler doesn't support C++14 so I cant use make_unique, which is what I think I'd need to use. Are there any alternatives to make_unique that work in C++11? Thanks in advance.
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <memory>
using namespace std;
unique_ptr<SavingsAccount> unqPtr = nullptr;
string uName, uPwd;
int main()
{
bool done = false;
while(!done)
{
int decision = showMenuOptions();
switch(decision)
{
case 1:
cout << "Enter your name: ";
getline(cin, uName);
// Error is here.. alternatives to make_unique??
unqSaPtr(new SavingsAccount(uName, uPwd));
break;
case 2:
// ...
break;
case 3:
done = false;
break;
default:
cerr << "Invalid option." << endl;
continue;
}
}
}
If any other code is needed for reference, just let me know.
Aucun commentaire:
Enregistrer un commentaire