#include <iostream>
#include <vector>
 
using namespace std;
 
class ctcChanID
{
public:
    void GetInfo(ctcChanID *m);
    int chanID;
    int type;
    string DN;
    int clientID;
};
 
void ctcChanID::GetInfo(ctcChanID *m)
{
 }
 
int main()
{
    vector<ctcChanID*> _ctc;
    for(int i = 0; i < 2 ; i++)
    {
        
        ctcChanID *a = new ctcChanID;
        cout << a << endl;
        a->chanID = i;
        a->type = 3;
        a->DN = "374847";
        a->clientID = 0;

        _ctc.push_back(a);
    }
 
    vector<ctcChanID*>::iterator iter;
    for(iter = _ctc.begin(); iter != _ctc.end(); ++iter)
    {
           cout << *iter->chanID << endl;
    }
 
    return 0;
}

when I compile the codes, it always generate the error:
error: request for member ‘chanID’ in ‘* iter. __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator-> [with _Iterator = ctcChanID**, _Container = std::vector<ctcChanID*, std::allocator<ctcChanID*> >]()’, which is of non-class type ‘ctcChanID*’

I cannot understand it,

Recommended Answers

All 3 Replies

solve it already

solve it already

What?! I really hope that is a typo and you meant: "solveD it already"....

>I really hope that is a typo and you meant: "solveD it already"....
As do I. It takes some big rocks to demand such a thing when you have three post and no discernible reputation in the community.

Anyway, in either case, it would be useful to know the answer. Change this:

cout << *iter->chanID << endl;

To this:

cout << (*iter)->chanID << endl;

The order of operations is such that the -> operator was acting on the iterator itself, not the item that the iterator refers to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.