Answer the question
In order to leave comments, you need to log in
How to correctly pass data from a functor?
I want to make my project according to MVC standards. Created a functor class that receives data from the server. I would like to request data from a functor from another translation unit in the form of some kind of container (for example, std::list). How can I correctly pass the container from this functor (it is desirable that this data is not stored in the functor, that is, we call the functor, it receives data, adds it to std:: list, passes this std:: list and ownership)?
Answer the question
In order to leave comments, you need to log in
There is clearly a specific task, but your explanation is too abstract. Describe what needs to be done.
In general, it is very likely that move semantics will do, namely:
- we describe the DataClass class that will store data
- when receiving data, we create an instance of the class in the form of std::unique_ptr and throw data there through the constructor (or method)
- we make the "get data" method which will return std::unique_ptr using std::move
- as soon as we want the data - we call the "get data" method and we get a smart pointer to the data, while no one else has it
If you need the data to be in different places - then you should use std:: shared_ptr
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question