member functions of vector?

Why can't member function of vector be used, when i am using them on vector a class..

for instance

I have this class.
1
2
3
4
5
6
7
8
9
10
11
12
13
Class Test
{

public:
vector<pair<int,int>> limeJuice;
~Test()
void merge(test &B)
{
      limeJuice.insert(limeJuice.end(),B.limeJuice.begin(),B.limeJuice.end());

};

};


In my main i have a vector <TEST> test_Objects;
when i call test_Objects.insert, or test_Objects.erase, i get the message that there is no member function to call..
Line 1: class must not be capitalized.

Line 6: missing ;

Line 7: Test must be capitalized.

In my main i have a vector <TEST> test_Objects;


I assume you mean: vector <Test> test_Objects;
C++ is case sensitive.

When you post a problem, a compilable snippet is appreciated, along with the exact text of the error you're getting. After making the above corrections, this compiles for me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <vector>
using namespace std;

class Test
{

public:
    vector<pair<int,int>> limeJuice;
    ~Test();
    void merge(Test &B)
    {   limeJuice.insert(limeJuice.end(),B.limeJuice.begin(),B.limeJuice.end());

    };

};

int main ()
{   vector <Test> test_Objects;
    Test    a;

    test_Objects.insert (test_Objects.begin(), a);
}


However, I don't know if my main represents what you're trying to do, since you didn't post anything for main.
it is exactly as you have written it exerts that
1
2
3
4
5
6
7
int main ()
{   vector <Test> test_Objects;
    Test    a;
int j = 1
int i = 5
 test_Objects.insert(j+1,i+1,test_Objects.end())
}
Last edited on
What are i and j? You don't show them.
I'm not a mind reader. You might think your snippet is obvious, but it's not.
Look again..
http://www.cplusplus.com/reference/vector/vector/insert/
those are the prototypes for `std::vector::insert()'
¿which one do you think you are using in test_Objects.insert(j+1,i+1,test_Objects.end())?
I hope it is this one
void insert (iterator position, InputIterator first, InputIterator last);
j is an integer
i is an integer
you are doing insert( int, int, iterator ) which does not exist
but the iterator itself isn't it an integer?... If not it it then possible to make it an iterator in some way?
to get integer from iterator subtract one iterator from anther. Most likely from begin .
> but the iterator itself isn't it an integer?
no. Iterators are used to traverse a container, and for that they have operations like getelement() and advance() ¿how do you expect 42.next() to work? ¿which container would be related to?


> possible to make it an iterator in some way?
yes, there are a lot of way.
¿what are you trying to accomplish?
¿what would be the result of doing test_Objects.insert(j+1,i+1,test_Objects.end())?
Last edited on
Topic archived. No new replies allowed.