What am I doing wrong at the last two lines in my code below? I receive an error:
request for member
‘name’in‘t.std::_List_iterator<_Tp>::operator* [with _Tp = a*]()’, which is of non-class type‘a*’
#include <dlfcn.h>
#include <iostream>
#include "/home/developer/Desktop/MsgSphSDK1/test1_sdk/libsdk_MS.hpp"
#include <list>
#include <typeinfo>
#include <string>
using namespace std;
class a
{
public:
string name;
int age;
};
int main()
{
a* l = new a();
l->name = "me";
l->age = 1;
list<a*> ls;
list<a*>::iterator t;
for (t = ls.begin(); t != ls.end(); ++t)
cout << (*t).name << endl;
}
You should write
tis an iterator,(*t)gives youa*(the pointer to the object of classa). So to get access to the member of the object you should use->, not..