Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:49:55+00:00 2026-06-02T07:49:55+00:00

I have a 2D vector which contains objects. std::vector<std::vector<List> > ListPos; ListPos.clear(); std::vector<List> initPV;

  • 0

I have a 2D vector which contains objects.

std::vector<std::vector<List> >   ListPos;

ListPos.clear();

std::vector<List> initPV;
ListPos.push_back(initPV);

List newList;

//... some code to determine where the object needs to go and vector resized to accommodate ...// 

ListPos[ThisY].insert(ListPos[ThisY].begin()+ThisX, newList);

Objects are created and the vector resized as needed, my question is how can I loop through the vector and delete any objects I’m not using(given some location data such asif(![3][7]) to free up memory.

Also can I do anything with the vector to free up memory for the space that the object was using after it being deleted?

| List | List | List |
-------------------------------
| List | List | Delted | List |
-------------------------------
| Deleted | List |

So in the above representation I have a 3 row vector with up to 4 cols, so where it says deleted that would be where the position of the objects have been deleted from.

I’m guessing that once the objects had been deleted from memory that the space in the vector would just.. ‘zero’?

I should note that where objects get deleted from say [2][0] I need to leave available for another object to go in its place, but cant allow [2][1] to take its place, if that makes sense. [2][1] needs to stay at [2][1]

I have tried the following (actual code)

for (std::vector<std::vector<List*> >::iterator i = Area::AreaControl.ListPos.begin(); i != Area::AreaControl.ListPos.end();++i) 
{
     for (std::vector<List*>::iterator j = i->begin(); j != i->end();++i)
     {
         if(j != Area::AreaControl.ListPos[0][0]) {
             // Delete
         }
     }
 }

But no dice 🙁

    error: conversion from ‘std::vector<List>::iterator {aka __gnu_cxx::__normal_iterator<List*, std::vector<List> >}’ to non-scalar type ‘std::vector<List*>::iterator {aka __gnu_cxx::__normal_iterator<List**, std::vector<List*> >}’ requested
src/Void_OnLoop.cpp:62:73: error: no match for ‘operator!=’ in ‘j != i.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = std::vector<List>*, _Container = std::vector<std::vector<List> >, __gnu_cxx::__normal_iterator<_Iterator, _Container>::pointer = std::vector<List>*]()->std::vector<_Tp, _Alloc>::end [with _Tp = List, _Alloc = std::allocator<List>, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<List*, std::vector<List> >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = List*]()’
src/Void_OnLoop.cpp:62:73: note: candidates are:
/usr/include/c++/4.6/ext/new_allocator.h:128:5: note: template<class _Tp> bool __gnu_cxx::operator!=(const __gnu_cxx::new_allocator<_Tp>&, const __gnu_cxx::new_allocator<_Tp>&)
/usr/include/c++/4.6/bits/stl_iterator.h:817:5: note: template<class _Iterator, class _Container> bool __gnu_cxx::operator!=(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
/usr/include/c++/4.6/bits/stl_iterator.h:811:5: note: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator!=(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
/usr/include/c++/4.6/bits/streambuf_iterator.h:200:5: note: template<class _CharT, class _Traits> bool std::operator!=(const std::istreambuf_iterator<_CharT, _Traits>&, const std::istreambuf_iterator<_CharT, _Traits>&)
/usr/include/c++/4.6/bits/basic_string.h:2497:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
/usr/include/c++/4.6/bits/basic_string.h:2485:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const _CharT*, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/basic_string.h:2473:5: note: template<class _CharT, class _Traits, class _Alloc> bool std::operator!=(const std::basic_string<_CharT, _Traits, _Alloc>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/postypes.h:223:5: note: template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)
/usr/include/c++/4.6/bits/stl_vector.h:1297:5: note: template<class _Tp, class _Alloc> bool std::operator!=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
/usr/include/c++/4.6/bits/allocator.h:137:5: note: template<class _Tp> bool std::operator!=(const std::allocator<_Tp1>&, const std::allocator<_Tp1>&)

As you can probably tell from my code, I’m no master.. Any suggestions will be highly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:49:56+00:00Added an answer on June 2, 2026 at 7:49 am

    In your first code block you define a std::vector<std::vector<List> >, i.e., a vector of vectors of List and in the second block you loop over std::vector<std::vector<List*> >, i.e., a vector of vector of pointer to List. Hence, the applied iterators are different types which cannot be converted into each other.

    I’d recommend to use typedefs for the inner and outer vector to ensure your types are consistent.

    And remember that erasing an element by an iterator invalidates the iterator, but returns a new iterator pointing to the next element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a container(any kind, probably std::map or std::vector) which contains objects of
I want to have some data cache which contains some objects which I can
I have a vector which contains a list of files to open and parse,
I have a set of objects in a Vector from which I'd like to
I have a std::vector containing a handful of numbers, which are not in any
I have the following function which creates a std::vector of iterators into another container:
I cannot sort the list which contains the pointers to objects of my template
My main frame contains JScrollPane which lists some objects. Through menu (pop up frame)
I have a singleton logger that contains a vector. Objects from outside can append
I have a vector-like class that contains an array of objects of type T

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.