Vector problem in C++ class

D

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
 
L

LaxTransplant

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;
 
H

Howard

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
 
L

Larry I Smith

dd said:
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
 
A

Andrew Koenig

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,293
Messages
2,571,500
Members
48,188
Latest member
GerardRush

Latest Threads

Top