Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vector(STL)

Posted on 2000-04-30
3
Medium Priority
?
349 Views
Last Modified: 2013-12-14
I use a vector to store some instances of a class. right now I need to remove all elements in the vector, I tried to use clear() function but was told "vector<classname>::clear() undefined". what's wrong?
0
Comment
Question by:Embt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2764390
that is the name of the function!   it should be defined.  Did you call it like a member function, i.e. like

vector<int> V;

V.clear():

Are you using the right include file?  You should use <vector> not <vector.h>.  (if you have one).  <vector> will place the vector class name in the ""std" namespace though, so you may wish to add a

using namespace std;

line too.
0
 

Author Comment

by:Embt
ID: 2764422
thanks for the response. I have no problem with header file etc. the problem is with the type of elements in the vector.  it is something like:

vector <MyClass> V;

when I called V.clear(), I was told member function vector<MyClass>::clear() undefined. if I use some other types like int, that will be fine.  I am not familiar with C++ class, I think I should define something in the class to make the function clear() work, right?
0
 
LVL 22

Accepted Solution

by:
nietod earned 120 total points
ID: 2764442
I think you are interpreting the eror message incorrectly--or it is a really bad error message (maybe that is even more likely!).

Anyways what I think is happening is that your class (MyClass) does not define some member function needed by the vector class.  To work within the vector class, your class needs to have:

a default constructor
a destructor
a copy constructor
an assigment operator (=).

None of these have to be explicitly defined though.  i.e. the compiler will trie to generate these if possible, but might fail for various reasons.

If that doesn't help, post your class definition, and the exact error message.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question