Custom class vector iterator error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 3
Reputation: dulusementara is an unknown quantity at this point 
Solved Threads: 0
dulusementara dulusementara is offline Offline
Newbie Poster

Custom class vector iterator error

 
0
  #1
Oct 3rd, 2008
I tried to write my code, and it looks like something like this (i cut some of them to make it readable).
class TimeSeriesDatum
{
public:	
	TimeSeriesDatum();
	//TimeSeriesDatum( double = 0, int = 0, string = "");	
	TimeSeriesDatum( double, int, string );
	
	// getter, setter...
private:
	double value;
};

// in the main
vector<TimeSeriesDatum> myvector;
vector<TimeSeriesDatum>::iterator it; // 4 errors in this line

And i've got 4 errors for the bold lines in my code, i wonder why. If you have ever had the same problem, can you let me know the solutions?

The errors are:
1) error C2653: 'vector<class TimeSeriesDatum,class std::allocator<class TimeSeriesDatum> >' : is not a class or namespace name
2) error C2065: 'iterator' : undeclared identifier
3) error C2146: syntax error : missing ';' before identifier 'it'
4) error C2065: 'it' : undeclared identifier

Thank you for your attention. I'll wait for your reply.
Last edited by dulusementara; Oct 3rd, 2008 at 6:36 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,625
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Custom class vector iterator error

 
0
  #2
Oct 3rd, 2008
My guess is that you forgot to include <vector> and/or using std::vector; statement
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: dulusementara is an unknown quantity at this point 
Solved Threads: 0
dulusementara dulusementara is offline Offline
Newbie Poster

Re: Custom class vector iterator error

 
0
  #3
Oct 3rd, 2008
yes, finally i found it.
I had this before:
  1. // coding A
  2. #include <vector>
  3. using std::vector;

and i changed it to:
  1. // coding B
  2. #include <vector>
  3. using namespace std;

and it produced no error. but i wonder why when i add another using statement, i.e. "using std::vector::iterator;" in coding B, also produced errors?

Thx.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,625
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Custom class vector iterator error

 
0
  #4
Oct 3rd, 2008
probably something else wrong with your program because this one compiles ok. using std::vector::iterator -- no such thing.
  1. #include <string>
  2. #include <vector>
  3. using std::vector;
  4.  
  5. using std::string;
  6.  
  7. int main()
  8. {
  9. vector<string> v;
  10. vector<string>::iterator it;
  11. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: dulusementara is an unknown quantity at this point 
Solved Threads: 0
dulusementara dulusementara is offline Offline
Newbie Poster

Re: Custom class vector iterator error

 
0
  #5
Oct 3rd, 2008
thx for your answer. yes, it's maybe because i tried to use visual C++ 6.0 at windows vista. hope that it won't be much different with the one at windows xp.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,625
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Custom class vector iterator error

 
0
  #6
Oct 3rd, 2008
ditch that compiler because it doesn't implement c++ very well. Better to get newest free Visual C++ 2008 Express -- you can download it free from Microsoft.

>>because i tried to use visual C++ 6.0 at windows vista
That's not the problem -- the problem is the compiler itself.
Last edited by Ancient Dragon; Oct 3rd, 2008 at 8:14 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC