GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Aug-2005, 00:06
jfritz jfritz is offline
New Member
 
Join Date: Aug 2005
Posts: 2
jfritz is on a distinguished road

templated object as member data in a class?


Hello, I'm getting compiler errors if I try to move a templated object from my main into a variable holder class. The object is an STL vector, and I'm delcaring it in my main like this:

Code:
vector<int> hits;

and this works fine. However, I'd like to have it as public data in a class. Such as this:

Code:
class statsHolder { public: vector<int> hits; }

although, for some reason, it doesn't like this. Of course, I guess I'm declaring it wrong or something. The compiler error says "expected ; before < token" on the line where I declare the hits vector. If I change the declaration in the class to this...

Code:
vector hits;

it gives another error that says that ISO forbids me to not include a type for the template. Would anyone help me out?
  #2  
Old 03-Aug-2005, 02:00
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by jfritz
Hello, I'm getting compiler errors if I try to move a templated object from my main into a variable holder class. The object is an STL vector, and I'm delcaring it in my main like this:

Code:
vector<int> hits;

and this works fine. However, I'd like to have it as public data in a class. Such as this:

Code:
class statsHolder { public: vector<int> hits; }

although, for some reason, it doesn't like this. Of course, I guess I'm declaring it wrong or something. The compiler error says "expected ; before < token" on the line where I declare the hits vector. If I change the declaration in the class to this...

Code:
vector hits;

it gives another error that says that ISO forbids me to not include a type for the template. Would anyone help me out?

At a first glance, I would say you either didn't include the vector header or didn't make the std namespace available (in the file where you declare your class).
Please make sure you do this in the file containing the class definition:

CPP / C++ / C Code:
#include <vector>
using std::vector;

If it still doesn't work, please post back and I'll take another look.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
Last edited by LuciWiz : 03-Aug-2005 at 03:30.
  #3  
Old 03-Aug-2005, 04:33
jfritz jfritz is offline
New Member
 
Join Date: Aug 2005
Posts: 2
jfritz is on a distinguished road
ah, yes, that was the problem, thank you. Namely, the using namespace std; -- i always take that for granted since it's always in the new file template in pretty much every compiler.
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 16:41
Error C2146: syntax error : missing ',' before identifier 'C4' mattchew008 C++ Forum 2 19-Dec-2004 07:06
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:43.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.