Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > declare a struct with c++ vectors in a header file...

Reply
Thread Tools

declare a struct with c++ vectors in a header file...

 
 
beet
Guest
Posts: n/a
 
      06-16-2008
Hi all,

I tried to declare a c++ struct like following in a header file; I
want to include
this header file in other files to create and access this struct.

------
1 #ifndef _SEARCHDATA_H_
2 #define _SEARCHDATA_H_
3
4 #include <vector>
5 #include <list>
6
7 typedef struct searchIterInfo searchIter;
8 struct searchIterInfo {
9 searchIterInfo ():
10 contPts(0), //continuous trial points
11 contFvs(0), //fv for cont points
12 contFerrors(0), //std errors for cont points
13 gradients(0), //list of gradients
14 intPts(0), //evaluated int points
15 intFvs(0), //function values for int points
16 intFerrors(0), //errors for int points
17 intPtList(0), //the monotone list of points
18 simList(0), //the simplex list
19 seedVals(0), //the seed values
20 hMtx(0) {}; //the estimated hesian matrix
21
22 vector< vector<double> > contPts;
23 vector<double> contFvs;
24 vector<double> contFerrors;
25 vector< vector<double> > gradients;
26 vector< vector<int> > intPts;
27 vector<double> intFvs;
28 vector<double> intFerrors;
29 list<int> intPtList;
30 list<int> simList;
31 vector<double> seedVals;
32 vector< vector<double> > hMtx;
33 int iterID; //the sample path index
34 double sampleSize; //the sample size for this sp
35 };
36 #endif
-----------------

I got compiler errors:

g++ -Wall -g -c retroSearch.cpp
In file included from retroSearch.cpp:3:
searchData.h:22: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:22: error: expected `;' before '<' token
searchData.h:23: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:23: error: expected `;' before '<' token
searchData.h:24: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:24: error: expected `;' before '<' token
searchData.h:25: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:25: error: expected `;' before '<' token
searchData.h:26: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:26: error: expected `;' before '<' token
searchData.h:27: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:27: error: expected `;' before '<' token
searchData.h:28: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:28: error: expected `;' before '<' token
searchData.h:29: error: ISO C++ forbids declaration of `list' with no
type
searchData.h:29: error: expected `;' before '<' token
searchData.h:30: error: ISO C++ forbids declaration of `list' with no
type
searchData.h:30: error: expected `;' before '<' token
searchData.h:31: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:31: error: expected `;' before '<' token
searchData.h:32: error: ISO C++ forbids declaration of `vector' with
no type
searchData.h:32: error: expected `;' before '<' token
searchData.h: In constructor `searchIterInfo::searchIterInfo()':
searchData.h:10: error: class `searchIterInfo' does not have any field
named `contPts'
searchData.h:11: error: class `searchIterInfo' does not have any field
named `contFvs'
searchData.h:12: error: class `searchIterInfo' does not have any field
named `contFerrors'
searchData.h:13: error: class `searchIterInfo' does not have any field
named `gradients'
searchData.h:14: error: class `searchIterInfo' does not have any field
named `intPts'
searchData.h:15: error: class `searchIterInfo' does not have any field
named `intFvs'
searchData.h:16: error: class `searchIterInfo' does not have any field
named `intFerrors'
searchData.h:17: error: class `searchIterInfo' does not have any field
named `intPtList'
searchData.h:18: error: class `searchIterInfo' does not have any field
named `simList'
searchData.h:19: error: class `searchIterInfo' does not have any field
named `seedVals'
searchData.h:20: error: class `searchIterInfo' does not have any field
named `hMtx'
searchData.h: At global scope:
searchData.h:36: error: expected constructor, destructor, or type
conversion before '<' token
searchData.h:37: error: `vector' was not declared in this scope
searchData.h:37: error: expected primary-expression before "int"
searchData.h:37: error: expected primary-expression before '&' token
searchData.h:37: error: expected primary-expression before ',' token
searchData.h:37: error: expected primary-expression before "double"
searchData.h:37: error: expected primary-expression before "double"
searchData.h:37: error: initializer expression list treated as
compound expression
searchData.h:38: error: variable or field `addPt' declared void
searchData.h:38: error: `vector' was not declared in this scope
searchData.h:38: error: expected primary-expression before "int"
searchData.h:38: error: expected primary-expression before '&' token
searchData.h:38: error: expected primary-expression before ',' token
searchData.h:38: error: expected primary-expression before "double"
searchData.h:38: error: expected primary-expression before "double"
searchData.h:38: error: initializer expression list treated as
compound express

****************

I am a beginer of c++ programming, so anyone pls help me.
Thanks a lot.

Beet
 
Reply With Quote
 
 
 
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      06-16-2008
On Jun 16, 2:01*pm, beet <whh...@gmail.com> wrote:
> * * *22 * * vector< vector<double> > contPts;

You need to qualify the names with std::
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      06-16-2008
"beet" <> wrote in message
news:ea358e60-cf58-4719-abba-...
> Hi all,
>
> I tried to declare a c++ struct like following in a header file; I
> want to include
> this header file in other files to create and access this struct.
>
> ------
> 1 #ifndef _SEARCHDATA_H_
> 2 #define _SEARCHDATA_H_
> 3
> 4 #include <vector>
> 5 #include <list>
> 6
> 7 typedef struct searchIterInfo searchIter;
> 8 struct searchIterInfo {
> 9 searchIterInfo ():
> 10 contPts(0), //continuous trial points
> 11 contFvs(0), //fv for cont points
> 12 contFerrors(0), //std errors for cont points
> 13 gradients(0), //list of gradients
> 14 intPts(0), //evaluated int points
> 15 intFvs(0), //function values for int points
> 16 intFerrors(0), //errors for int points
> 17 intPtList(0), //the monotone list of points
> 18 simList(0), //the simplex list
> 19 seedVals(0), //the seed values
> 20 hMtx(0) {}; //the estimated hesian matrix
> 21
> 22 vector< vector<double> > contPts;


std::vector<std::vector<double>> contPts;

> 23 vector<double> contFvs;


std::vector<double> contFvs;

> 24 vector<double> contFerrors;


std::vector<double> contFerrors;
etc...
[SNIP]


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
declare a struct with c++ vectors in a header file... beet C++ 5 06-17-2008 08:23 PM
c++ primer statement about vectors containing vectors pauldepstein@att.net C++ 3 03-26-2008 06:22 PM
Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)? Ruby 0 09-14-2005 05:47 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57