Just wondering, because of a problem I am running into, is it possible to create a vector of pointers? And if so, how? Specifically concerning using iterators and .begin()
Yes, sure.
// TestCPP.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
using namespace std;
class c
{
public:
void virtual func() = 0;
};
class sc:public c
{
public:
void func(){cout<<"using func";}
};
int _tmain(int argc, _TCHAR* argv[])
{
sc cobj;
vector cvect;
cvect.push_back(&cobj);
vector::iterator citer;
for(citer=cvect.begin();citerfunc();
}
return 0;
}
Please note the declaration of vector
and the use of cvect.push_back(&cobj)
.
From the code provided, you are using iterator in a wrong way. To access the member an iterator is pointing to you must use *citer
instead of citer
alone.