As declared above, I wish to access an object from the vector which contains an abstract class. I'm fairly new.
Account* c = new Current;
vtrAcc.push_back(c("test", 0));
Where "test"
is a name and 0
is account ID.
Writing this, throws an error:
expression preceding parentheses of apparent call must have (pointer-to-) function C/C++(109)
We're required to create multiple instances of accounts, thus I use vectors, however, I fail to understand (pointers are hard) how to add parameters to initialize my constructor? Does Account* c = new Current;
call its' default constructor?
I expect this to work for now just to understand the thought behind it. Looking throughout StackOverflow I did find this TOPIC from 10 years ago, I understand it. But how do I adapt that with pointers?
try
Account* c = new Current("test", 0);
vtrAcc.push_back(c);
if your vtrAcc is a pointer to account type vector<Account*>vtrAcc;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.