Похожие чаты

Hi guys, i defined my own class that is basically

a (private) vector of my own objects + some additional variables, how do i make the object instances of that class have the same methods as a vector has? for example:

MyCont cont = {my objects here}
and i want to do things like:
cont[2]
cont.push_back()
cont.end()
etc.

i see 2 solutions: return the vector and do stuff on it:
// in the class:
std::vector<Obj> vector(){
return m_vector;
}
// in the main file:
cont.vector()[2]
cont.vector().push_back()

or, possibly, somehow adding all of the methods of the standard vector class and using them as a sort of an interface:
//in the class:
void push_back(Obj& obj){
m_vector.push_back(obj);
}
// and the same for each method

but that seems very error-prone and just overall unstable, and i wonder if there's a more elegant workaround to what i'm looking for / how the same problem is solved in more professional apps

2 ответов

26 просмотров

Hey, take a look at this stackoverflow Question, which adds another option to your list, and also discusses the problems of that option. Hope you will find it useful: https://stackoverflow.com/questions/4353203/thou-shalt-not-inherit-from-stdvector

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта