« first day (1967 days earlier)      last day (888 days later) » 

2:27 AM
5 messages moved from Lounge<C++>
 
 
6 hours later…
8:40 AM
in which order are virtual destructors called?
this is my code:
std::vector< std::unique_ptr<Box> >Storage;

Storage.push_back(std::make_unique<Box>(20, 30, 40));
Storage.push_back(std::make_unique<ToughPack>(20, 30, 40));
Storage.push_back(std::make_unique<Carton>(20, 30, 40,"Plastic"));
Box class has a virtual destructor and Toughpack and Carton use inheritance from Box
however the output looks like this:
"Box destructor called
Toughpack destructor called
Box destructor called
Carton destructor called
Box destructor called" (I put std::cout in all destructors to keep track )
can someone explain why it is not Carton then Toughpack then Box being destroyed?
 
Vector contents don't get destroyed in reverse order for you. I don't think destruction order of vector elements is defined
@Amiu seems fine to me. Assumes that there's always only one first-name and only one last name, but other than that seems mostly more efficient than what I posted. Mostly because it doesn't follow the restriction you originally posted "with the use of only one std::getline"
 
9:28 AM
how to pass vector of pointers and print them using a template function?
code :
template <class T>
void display(const std::vector<T*>& vect)
{
for (size_t i{}; i < vect.size(); ++i)
{
vect[i]->who();
}
}
this gives an error saying : Severity Code Description Project File Line Suppression State
Error C2784 'void display(const std::vector<T*,std::allocator<T*>> &)': could not deduce template argument for 'const std::vector<T*,std::allocator<T*>> &' from 'std::vector<std::unique_ptr<Person,std::default_delete<Person>>,std::allocator<std::unique_ptr<Person,std::default_delete<Person>>>>'
 
you can't treat std::unique_ptr just like a normal pointer for template argument deduction
 
is there a better way to make a function template that can be used to print vector of unique_ptr?
now I tried to fix it like this
template <class T>
void display(std::vector<std::unique_ptr<T>> vect)
{
for (size_t i{}; i < vect.size(); ++i)
{
vect[i]->who();
}
}
but this gives another error: 'trying to reference a deleted function'. But there are no deleted functions so I'm not sure how that happened?
'who' is a virtual function, could that be an issue?
 
the deleted function is trying to copy the unique_ptr
because you're taking the vector by value
 
how to fix this? @PeterT
 
9:43 AM
take the vector by reference or const reference like you did before
 
ok thanks for the help
 
10:13 AM
what is a good way to implement std::make_unique for a C++11 compiler?
 
nwp
33
Q: How to implement make_unique function in C++11?

user1899020My compiler doesn't support make_unique. How to write one? template< class T, class... Args > unique_ptr<T> make_unique( Args&&... args );

 
10:33 AM
ok I'll check that out
 
 
4 hours later…
3:00 PM
Can someone help me with the libCurl multi-interface?

Currently, I am creating a pool of CURL handles and for each request, I am getting a handle from the pool and doing curl_easy_perform()

I read curl_multi_perform is better than curl_easy_perform.
I have seen the examples in libCurl but all the examples were collecting the response in a loop. Only exiting when all the response is received.
But I want to return a response immediately for each request whenever its available
Can someone guide me in some technique?
 
 
2 hours later…
4:54 PM
@nwp Thanks! Next, I'm going to look it up in the standard based on your hints.
 
5:41 PM
Good evening, i am currently writing a php extension in C++ and i wonder how to pass parameter to a PHP_METHOD in the C++ File. I thought it would work like:

PHP_METHOD('class', 'method) {
long param1, param2, param2
}

and i called it like: $object->method(param1, param2, param3);

Has anyone maybe an idea? i am unfortunately quite new to c++ and stuck on this
 
1 message moved from Lounge<C++>
Looks like there are some macros you need to set up, but in terms of inbound parameters you don't define them in the method defintion
 
6:07 PM
Thank you, I will look into it
 
 
2 hours later…
8:22 PM
is there any way to deduce a the size of a pointer to an array ?
I'm thinking of this but it doesn't work:
template<typename T, size_t N>
size_t size(T* array[N])
{
return N;
}
 
um in what sense? Because the size of a pointer itself is constant generally... OH
yeah that will only work if you have the array
if you're looking at just the pointer to the array you're FUBAR
also std::size exists to do this already
 
@Electrical_engineer_student en.cppreference.com/w/cpp/iterator/size
just make your own version of that... not in namespace std
 
8:36 PM
ok will do
 

« first day (1967 days earlier)      last day (888 days later) »