Category : stdvector

when i try to call void player::showCardInHand() func in main function, the function gives only one card name rather than five card name as output. What is the problem in the code? You can see the code below: void player::drawCardRandomly() { if (/*_myTurn*/true && _cardCountInHand < 7) { srand(time(NULL)); int randomCardIndex = rand() % 12; ..

Read more

I’m building a 2D platformer game, and every entity in my game inherits from class Entity. I have a std::vector<std::unique_ptr<Entity>> entities to dynamically allocate these entities. I want to also polymorphically check for collision from the driver code: for(int i = 0; i < entities.size();i++){ for(int j = 0; j < entities.size();j++) entities[i]->checkCollision(*j); } The ..

Read more

I am trying to compile a opencv program and I am getting the error invalid initialization of reference of type ‘cv::InputArray {aka const cv::_InputArray&}’ from expression of type ‘std::vector<double, std::allocator<double> >::const_iterator (strangely I only get this error when building it in my Jetson Xavier. When I build it in my PC no problem arises) The ..

Read more

I use multithreading to read and write a global variable std::deque<int> g_to_be_downloaded_tasks, and I use std::mutex to protect concurrent access. but ThreadB can not get element after ThreadA inserts an element to this vector, ThreadA g_to_be_downloaded_tasks_mutex.try_lock(); g_to_be_downloaded_tasks.push_back(temp); g_to_be_downloaded_tasks_mutex.unlock(); ThreadB: ThreadB gets 0 after using g_to_be_downloaded_tasks.size() g_to_be_downloaded_tasks_mutex.try_lock(); if(g_to_be_downloaded_tasks.size() > 0) { curr_task = g_to_be_downloaded_tasks.front(); } g_to_be_downloaded_tasks_mutex.unlock(); ..

Read more