473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Vector problem in C++ class

dd
Dears,
Can STL vector be a member in class, such as the following codes showed:

#ifndef __SB_SWLISTCTRL_H
#define __SB_SWLISTCTRL_H

class SBSWListCtrl : public wxListCtrl
{
public:
HINSTANCE hdll;
typedef vector<string> softwares;
SBSWListCtrl(wxWindow* parent, wxWindowID id);
void Connect();
void ShowSW();
};
#endif

When I compile the program, compiler gave me the following error

header/sbswlistctrl.h:8: `string' was not declared in this scope
header/sbswlistctrl.h:8: ISO C++ forbids declaration of `vector' with no type
header/sbswlistctrl.h:8: template-id `vector<<expression error> >' used as a
declarator
header/sbswlistctrl.h:8: parse error before `;' token

What is my problem?

Simon
27/Apr/2005
Jul 23 '05 #1
6 5194
typedef vector<string> softwares;


You are only typedefing the definition of a vector of strings. You
should do this within the typedef:

typedef vector<std::string> softwares;

Now, you need to declare a variable of type softwares.

sofwares sofwareVector;

Jul 23 '05 #2

<La***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
typedef vector<string> softwares;


You are only typedefing the definition of a vector of strings. You
should do this within the typedef:

typedef vector<std::string> softwares;

Now, you need to declare a variable of type softwares.

sofwares sofwareVector;


And remember to #include <string.h>.

-Howard

Jul 23 '05 #3
dd wrote:
Dears,
Can STL vector be a member in class, such as the following codes showed:

#ifndef __SB_SWLISTCTRL_H
#define __SB_SWLISTCTRL_H

class SBSWListCtrl : public wxListCtrl
{
public:
HINSTANCE hdll;
typedef vector<string> softwares;
SBSWListCtrl(wxWindow* parent, wxWindowID id);
void Connect();
void ShowSW();
};
#endif

When I compile the program, compiler gave me the following error

header/sbswlistctrl.h:8: `string' was not declared in this scope
header/sbswlistctrl.h:8: ISO C++ forbids declaration of `vector' with no type
header/sbswlistctrl.h:8: template-id `vector<<expression error> >' used as a
declarator
header/sbswlistctrl.h:8: parse error before `;' token

What is my problem?

Simon
27/Apr/2005


Here's one possibility:
#ifndef __SB_SWLISTCTRL_H
#define __SB_SWLISTCTRL_H

#include <string>
#include <vector>

typedef std::vector< std::string > StrVector;

class SBSWListCtrl : public wxListCtrl
{
public:
HINSTANCE hdll;
StrVector softwares;
SBSWListCtrl(wxWindow* parent, wxWindowID id);
void Connect();
void ShowSW();
};
#endif

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #4

"Howard" <al*****@hotmail.com> wrote in message
news:4p*********************@bgtnsc05-news.ops.worldnet.att.net...

<La***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
typedef vector<string> softwares;


You are only typedefing the definition of a vector of strings. You
should do this within the typedef:

typedef vector<std::string> softwares;

Now, you need to declare a variable of type softwares.

sofwares sofwareVector;


And remember to #include <string.h>.


Oops! Make that <string>, not <string.h>.
-H

Jul 23 '05 #5
Howard wrote:
<La***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
typedef vector<string> softwares;


You are only typedefing the definition of a vector of strings. You
should do this within the typedef:

typedef vector<std::string> softwares;

Now, you need to declare a variable of type softwares.

sofwares sofwareVector;

And remember to #include <string.h>.


What's that for? Did you mean "remember to #include <string>"?
Jul 23 '05 #6
"dd" <hi******@yahoo.com> wrote in message
news:d7*************************@posting.google.co m...
Can STL vector be a member in class, such as the following codes showed:

#ifndef __SB_SWLISTCTRL_H
#define __SB_SWLISTCTRL_H

class SBSWListCtrl : public wxListCtrl
{
public:
HINSTANCE hdll;
typedef vector<string> softwares;
SBSWListCtrl(wxWindow* parent, wxWindowID id);
void Connect();
void ShowSW();
};
#endif

When I compile the program, compiler gave me the following error

header/sbswlistctrl.h:8: `string' was not declared in this scope
header/sbswlistctrl.h:8: ISO C++ forbids declaration of `vector' with no
type
header/sbswlistctrl.h:8: template-id `vector<<expression error> >' used as
a
declarator
header/sbswlistctrl.h:8: parse error before `;' token

What is my problem?


Your first error message says it all: There's no declaration of the
"string" type.

Which means that you need to do one (or both) of the following:

#include <string>

typedef vector<std::string> softwares;
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan Benn | last post by:
(VC6) When I use the STL <vector> template as follows: #include <vector> .... vector<CString> m_nameList; // Names of the chips I get these compiler warnings : C:\Program...
11
by: sw | last post by:
Hi, Is it possible to insert a class <vec> which has a vector<double> member, into the vector<vec> veclist for e.g? I've been getting compilation errors when trying to insert using the vector...
9
by: uotani.arisa | last post by:
Hi, Can someone tell me how to declare a pointer to a vector of pointers? I'm just not sure how to do this... I've tried essentially the following: vector<string *> * v; ....
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
12
by: mast2as | last post by:
Hi everyone I am working on some code that uses colors. Until recently this code used colors represented a tree floats (RGB format) but recently changed so colors are now defined as spectrum....
1
by: krunalbauskar | last post by:
Hi, Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. For example - <snippet> #include <iostream> #include <vector>
6
by: Jia | last post by:
Hi all, I have a class foo which has a static vector of pointers of type base class, and a static function to set this vector. #include <iostream> #include <vector> using namespace std;...
4
by: helge | last post by:
What is the best way to implement a vector in space R3, i.e a vector holding three floats, supporting arithmetic operations, dot and cross product etc in c++? is there a standard library class for...
3
by: Ramon F Herrera | last post by:
Newbie alert: I come from C programming, so I still have that frame of mind, but I am trying to "Think in C++". In C this problem would be solved using unions. Hello: Please consider the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.