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:

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

#endif
 
Reply With Quote
 
 
 
 
joseph cook
Guest
Posts: n/a
 
      06-16-2008
> * * * 1 #ifndef _SEARCHDATA_H_
> * * * 2 #define _SEARCHDATA_H_


Names cannot begin with an underscore and a Capital letter (they are
reserved by the implementation)

> * * * 7 typedef struct searchIterInfo searchIter;


I suspect this is a C-ism, and is not something you need in C++ code.

> * * * 8 struct searchIterInfo {
> * * * 9 * * searchIterInfo ():
> * * *10 * * contPts(0), * * * //continuous trial points>


There's no need to zero initialize std::vector types here...

Joe Cook
 
Reply With Quote
 
 
 
 
Eric Pruneau
Guest
Posts: n/a
 
      06-17-2008

"beet" <(E-Mail Removed)> a écrit dans le message de news:
e3e5243c-c4e4-41cb-8a43-d7e6d0c02cd1...oglegroups.com...
> Hi all,
>
> I tried to declare a c++ struct like following in a header file:
>
> ------
> 1 #ifndef _SEARCHDATA_H_
> 2 #define _SEARCHDATA_H_
> 3
> 4 #include <vector>
> 5 #include <list>
> 6


add :
using namespace std;

or you gonna have to be type 'std::vector' instead of just 'vector'.
vector (list too) is a class inside the namespace std.


> 7 typedef struct searchIterInfo searchIter;


Looks like C style programming here (line 7) and by the way you are not
using 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


why are you doing something like contPts(0). This actually calls the
constructor of vector with 0 as a parameter.
So after that your vector has size 0... useless

> 22 vector< vector<double> > contPts;


when I have a line like that, I usually do:

typedef vector<double> VecDouble;
vector<VecDouble> contPtrs;

That way you avoid the >> problem

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




 
Reply With Quote
 
beet
Guest
Posts: n/a
 
      06-17-2008
On Jun 16, 11:28*pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * Eric Pruneau:
>
> > * "beet" <(E-Mail Removed)>:

>
> >> I tried to declare a c++ struct like following in a header file:

>
> >> ------
> >> * * *1 #ifndef _SEARCHDATA_H_
> >> * * *2 #define _SEARCHDATA_H_

>
> Never define names starting with underscore followed by uppercase letter.
>
> Those are reserved for the C++ implementation.
>
> That also goes for use of double underscore.
>
> >> * * *3
> >> * * *4 #include <vector>
> >> * * *5 #include <list>
> >> * * *6

>
> > add :
> > using namespace std;

>
> > or you gonna have to be type 'std::vector' instead of just 'vector'.
> > vector (list too) is a class inside the namespace std.

>
> I'm sorry, but that is extremely bad advice.
>
> Never add "using namespace std;" in a header file. It will force unqualified
> names from the standard library, on all code that uses the header file. And in
> particular, "string" and "vector" are commonly used names for other things than
> the standard library classes, and you really don't want to screw up things for
> code that uses those names *-- *that's why the standard library uses "std::".
>
> Conversely, when you see "using namespace std;" in a header file then you know
> that the author is incompetent or an utter novice.
>
> Cheers, & hth.,
>
> - Alf
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?


Thanks for your replies...
I modified a bit my code according to your comments, but it seems
problems with declaration of functions:

g++ -Wall -g -c searchData.cpp
searchData.cpp: In function `int searchPt(std::vector<int,
std::allocator<int> >&, searchIter&, double&, double&)':
searchData.cpp:46: warning: comparison between signed and unsigned
integer expressions
g++ -Wall -g -o runinv functionfile.o retroSearch.o searchData.o
simlib.o myinv.o mxCalc.o optSolver.o
optSolver.o(.text+0x1d27): In function `egSearch(std::vector<double,
std::allocator<double> >&, double, float&, double&, searchIterInfo&,
float)':
/home/wang75/myResearch/generic/simContSearch/optSolver.cpp:351:
undefined reference to `getInitStep(std::vector<double,
std::allocator<double> > const&, std::vector<double,
std::allocator<double> >&, int, float, int)'
optSolver.o(.text+0x1ffb):/home/wang75/myResearch/generic/
simContSearch/optSolver.cpp:382: undefined reference to
`getInitStep(std::vector<double, std::allocator<double> > const&,
std::vector<double, std::allocator<double> >&, int, float, int)'
optSolver.o(.text+0x4039): In function `fcn(std::vector<double,
std::allocator<double> > const&, std::vector<double,
std::allocator<double> >&, double, searchIterInfo&, int, int, float)':
/home/wang75/myResearch/generic/simContSearch/optSolver.cpp:711:
undefined reference to `simplexInterp(std::vector<double,
std::allocator<double> > const&, std::vector<std::vector<int,
std::allocator<int> >, std::allocator<std::vector<int,
std::allocator<int> > > >&, std::vector<double, std::allocator<double>
>&, std::vector<int, std::allocator<int> >&, int, float, int)'

optSolver.o(.text+0x465c): In function `fcnPart(std::vector<double,
std::allocator<double> > const&, std::vector<double,
std::allocator<double> >&, double, int, searchIterInfo&, int, int,
float)':
/home/wang75/myResearch/generic/simContSearch/optSolver.cpp:768:
undefined reference to `simplexInterp(std::vector<double,
std::allocator<double> > const&, std::vector<std::vector<int,
std::allocator<int> >, std::allocator<std::vector<int,
std::allocator<int> > > >&, std::vector<double, std::allocator<double>
>&, std::vector<int, std::allocator<int> >&, int, float, int)'

collect2: ld returned 1 exit status
make: *** [runinv] Error 1

shell returned 2

----my code ---

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

--------------


Really appreciate your help.
Beet
 
Reply With Quote
 
beet
Guest
Posts: n/a
 
      06-17-2008
On Jun 17, 1:17*pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * beet:
>
>
>
>
>
> > On Jun 16, 11:28 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> >> * Eric Pruneau:

>
> >>> * "beet" <(E-Mail Removed)>:
> >>>> I tried to declare a c++ struct like following in a header file:
> >>>> ------
> >>>> * * *1 #ifndef _SEARCHDATA_H_
> >>>> * * *2 #define _SEARCHDATA_H_
> >> Never define names starting with underscore followed by uppercase letter.

>
> >> Those are reserved for the C++ implementation.

>
> >> That also goes for use of double underscore.

>
> >>>> * * *3
> >>>> * * *4 #include <vector>
> >>>> * * *5 #include <list>
> >>>> * * *6
> >>> add :
> >>> using namespace std;
> >>> or you gonna have to be type 'std::vector' instead of just 'vector'.
> >>> vector (list too) is a class inside the namespace std.
> >> I'm sorry, but that is extremely bad advice.

>
> >> Never add "using namespace std;" in a header file. It will force unqualified
> >> names from the standard library, on all code that uses the header file. And in
> >> particular, "string" and "vector" are commonly used names for other things than
> >> the standard library classes, and you really don't want to screw up things for
> >> code that uses those names *-- *that's why the standard library uses "std::".

>
> >> Conversely, when you see "using namespace std;" in a header file then you know
> >> that the author is incompetent or an utter novice.

>
> >> Cheers, & hth.,

>
> >> - Alf

>
> >> --
> >> A: Because it messes up the order in which people normally read text.
> >> Q: Why is it such a bad thing?
> >> A: Top-posting.
> >> Q: What is the most annoying thing on usenet and in e-mail?

>
> Please don't quote signatures.
>
> > Thanks for your replies...
> > I modified a bit my code according to your comments, but it seems
> > problems with declaration of functions:

>
> > g++ -Wall -g -c searchData.cpp
> > searchData.cpp: In function `int searchPt(std::vector<int,
> > std::allocator<int> >&, searchIter&, double&, double&)':
> > searchData.cpp:46: warning: comparison between signed and unsigned
> > integer expressions

>
> This is from code you haven't shown. It's just a warning but you should fix it.
> * Typical fix to is use 'size_t' for a loop variable.
>
> > g++ -Wall -g -o runinv functionfile.o retroSearch.o searchData.o
> > simlib.o myinv.o mxCalc.o optSolver.o
> > optSolver.o(.text+0x1d27): In function `egSearch(std::vector<double,
> > std::allocator<double> >&, double, float&, double&, searchIterInfo&,
> > float)':
> > /home/wang75/myResearch/generic/simContSearch/optSolver.cpp:351:
> > undefined reference to `getInitStep(std::vector<double,
> > std::allocator<double> > const&, std::vector<double,
> > std::allocator<double> >&, int, float, int)'

>
> This an undefined reference because the message says "undefined reference"..
>
> That means the object files you're linking don't have an implementation of that
> function.
>
> Probably it's due to a signature mismatch for something you think is an
> implementation.
>
> > optSolver.o(.text+0x1ffb):/home/wang75/myResearch/generic/
> > simContSearch/optSolver.cpp:382: undefined reference to
> > `getInitStep(std::vector<double, std::allocator<double> > const&,
> > std::vector<double, std::allocator<double> >&, int, float, int)'
> > optSolver.o(.text+0x4039): In function `fcn(std::vector<double,
> > std::allocator<double> > const&, std::vector<double,
> > std::allocator<double> >&, double, searchIterInfo&, int, int, float)':
> > /home/wang75/myResearch/generic/simContSearch/optSolver.cpp:711:
> > undefined reference to `simplexInterp(std::vector<double,

>
> "undefined reference"
>
> > std::allocator<double> > const&, std::vector<std::vector<int,
> > std::allocator<int> >, std::allocator<std::vector<int,
> > std::allocator<int> > > >&, std::vector<double, std::allocator<double>
> >> &, std::vector<int, std::allocator<int> >&, int, float, int)'

> > optSolver.o(.text+0x465c): In function `fcnPart(std::vector<double,
> > std::allocator<double> > const&, std::vector<double,
> > std::allocator<double> >&, double, int, searchIterInfo&, int, int,
> > float)':
> > /home/wang75/myResearch/generic/simContSearch/optSolver.cpp:768:
> > undefined reference to `simplexInterp(std::vector<double,

>
> "undefined reference"
>
> > std::allocator<double> > const&, std::vector<std::vector<int,
> > std::allocator<int> >, std::allocator<std::vector<int,
> > std::allocator<int> > > >&, std::vector<double, std::allocator<double>
> >> &, std::vector<int, std::allocator<int> >&, int, float, int)'

> > collect2: ld returned 1 exit status
> > make: *** [runinv] Error 1

>
> > shell returned 2

>
> > ----my code ---

>
> > * * * 1 #ifndef _searchData_
> > * * * 2 #define _searchData_

>
> Generally only use ALL UPPERCASE for macro names, and never use that convention
> for other names, so as to avoid possible name collisions (macros don't respect
> scopes) *-- *this is a FAQ.
>
> I should have been less specific about underscore advice.
>
> As a rule, never use any leading underscore whatsoever, because in the global
> namespace those names are reserved for the implementation, and it's easiest to
> just never use them rather than remember where they're not reserved.
>
> > * * * 3 #include <vector>
> > * * * 4 #include <list>
> > * * * 5
> > * * * 6 typedef struct searchIterInfo {

>
> This is a C-ism, not necessary in C++. The C construct
>
> * *typedef struct { blah blah } SomeName;
>
> is, in C++, better expressed as
>
> * *struct SomeName { blah blah };
>
> > * * * 7 * * searchIterInfo ():
> > * * * 8 * * contPts(0), * * * //continuous trial points
> > * * * 9 * * contFvs(0), * * * //fv for cont points
> > * * *10 * * contFerrors(0), * //std errors for cont points
> > * * *11 * * gradients(0), * * //list of gradients
> > * * *12 * * intPts(0), * * * *//evaluated int points
> > * * *13 * * intFvs(0), * * * *//function values for int points
> > * * *14 * * intFerrors(0), * *//errors for int points
> > * * *15 * * intPtList(0), * * //the monotone list of points
> > * * *16 * * simList(0), * * * //the simplex list
> > * * *17 * * seedVals(0), * * *//the seed values
> > * * *18 * * hMtx(0) {}; * * * //the estimated hesian matrix

>
> Extraneous semicolon after right brace.
>
> Anyway you don't need to define the vector initializations because they're what
> you get by default.
>
> What you do need to initialize is what you've forgotten to initialize, namely
> the members of built-in type 'iterID' and 'sampleSize': since they're not of
> class type they don't have automatic default initialization.
>
> > * * *19
> > * * *20 * * std::vector< std::vector<double> > contPts;
> > * * *21 * * std::vector<double> * * * * * contFvs;
> > * * *22 * * std::vector<double> * * * * * contFerrors;
> > * * *23 * * std::vector< std::vector<double> > gradients;
> > * * *24 * * std::vector< std::vector<int> > * *intPts;
> > * * *25 * * std::vector<double> * * * * * intFvs;
> > * * *26 * * std::vector<double> * * * * * intFerrors;
> > * * *27 * * std::list<int> * * * * * * * *intPtList;
> > * * *28 * * std::list<int> * * * * * * * *simList;
> > * * *29 * * std::vector<int> * * * * * * *seedVals;
> > * * *30 * * std::vector< std::vector<double> > hMtx;
> > * * *31 * * int iterID; * * * * * //the sample path index
> > * * *32 * * double sampleSize; * *//the sample size for this sp

>
> Since the above doesn't communicate any purpose to me, it probably will not
> communicate any purpose to you either when you have been away from the code for
> some time. So better more self-describing names would probably be a good idea.
> It's also possible, but by no means sure, that you're doing an unnecessary
> inversion of data structure, using a struct of vectors when problem domain calls
> for a vector of structs -- generally a struct of like vectors indicate that.
>
> > * * *33 } searchIter;
> > * * *34
> > * * *35 std::vector<int> getBestIntPt(searchIter &);
> > * * *36 int searchPt(std::vector<int> &, searchIter &, double &,
> > double &);
> > * * *37 void addPt(std::vector<int> &, searchIter &, double fv, double
> > fr);
> > * * *38
> > * * *39 #endif

>
> Cheers, & hth.,
>
> - Alf
>


> - Show quoted text -


Thanks Alf,

the functions are declared and defined in simInterp.h and
simInterp.cpp respectively:
----code---

#ifndef __SIMINTERP_H__
#define __SIMINTERP_H__

void getBinary(int, vector<int> &, int);
int getDecimal(vector<int> &);
void simplexInterp(vector<double> const&, vector< vector<int> > &,
vector<double> &,
vector<int> &, int = 0, float = 1.0, int = 0);
double getInitStep(const vector<double>&, vector<double> &, int = 0,
float = 1.0, int = 0);

#endif
*****

#include "simInterp.h"
#include <vector>
#include <iostream>
#include <math.h>
void simplexInterp(vector<double> const& x, vector< vector<int> >
&simVerts, vector<double> &wts,
vector<int> &permu, int simCode, float csize, int patCode)
{
...
}

double getInitStep(const vector<double> &x, vector<double> &d, int
simCode, float csize, int bMax)
{
....
}

-----end of code---

I cannot find anything wrong here.

again, thank you very much for your kind help.

Beet
 
Reply With Quote
 
beet
Guest
Posts: n/a
 
      06-17-2008
On Jun 17, 1:17*pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * beet:
>
>
>
>
>
> > On Jun 16, 11:28 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> >> * Eric Pruneau:

>
> >>> * "beet" <(E-Mail Removed)>:
> >>>> I tried to declare a c++ struct like following in a header file:
> >>>> ------
> >>>> * * *1 #ifndef _SEARCHDATA_H_
> >>>> * * *2 #define _SEARCHDATA_H_
> >> Never define names starting with underscore followed by uppercase letter.

>
> >> Those are reserved for the C++ implementation.

>
> >> That also goes for use of double underscore.

>
> >>>> * * *3
> >>>> * * *4 #include <vector>
> >>>> * * *5 #include <list>
> >>>> * * *6
> >>> add :
> >>> using namespace std;
> >>> or you gonna have to be type 'std::vector' instead of just 'vector'.
> >>> vector (list too) is a class inside the namespace std.
> >> I'm sorry, but that is extremely bad advice.

>
> >> Never add "using namespace std;" in a header file. It will force unqualified
> >> names from the standard library, on all code that uses the header file. And in
> >> particular, "string" and "vector" are commonly used names for other things than
> >> the standard library classes, and you really don't want to screw up things for
> >> code that uses those names *-- *that's why the standard library uses "std::".

>
> >> Conversely, when you see "using namespace std;" in a header file then you know
> >> that the author is incompetent or an utter novice.

>
> >> Cheers, & hth.,

>
> >> - Alf

>
> >> --
> >> A: Because it messes up the order in which people normally read text.
> >> Q: Why is it such a bad thing?
> >> A: Top-posting.
> >> Q: What is the most annoying thing on usenet and in e-mail?

>
> Please don't quote signatures.
>
> > Thanks for your replies...
> > I modified a bit my code according to your comments, but it seems
> > problems with declaration of functions:

>
> > g++ -Wall -g -c searchData.cpp
> > searchData.cpp: In function `int searchPt(std::vector<int,
> > std::allocator<int> >&, searchIter&, double&, double&)':
> > searchData.cpp:46: warning: comparison between signed and unsigned
> > integer expressions

>
> This is from code you haven't shown. It's just a warning but you should fix it.
> * Typical fix to is use 'size_t' for a loop variable.
>
> > g++ -Wall -g -o runinv functionfile.o retroSearch.o searchData.o
> > simlib.o myinv.o mxCalc.o optSolver.o
> > optSolver.o(.text+0x1d27): In function `egSearch(std::vector<double,
> > std::allocator<double> >&, double, float&, double&, searchIterInfo&,
> > float)':
> > /home/wang75/myResearch/generic/simContSearch/optSolver.cpp:351:
> > undefined reference to `getInitStep(std::vector<double,
> > std::allocator<double> > const&, std::vector<double,
> > std::allocator<double> >&, int, float, int)'

>
> This an undefined reference because the message says "undefined reference"..
>
> That means the object files you're linking don't have an implementation of that
> function.
>
> Probably it's due to a signature mismatch for something you think is an
> implementation.
>
> > optSolver.o(.text+0x1ffb):/home/wang75/myResearch/generic/
> > simContSearch/optSolver.cpp:382: undefined reference to
> > `getInitStep(std::vector<double, std::allocator<double> > const&,
> > std::vector<double, std::allocator<double> >&, int, float, int)'
> > optSolver.o(.text+0x4039): In function `fcn(std::vector<double,
> > std::allocator<double> > const&, std::vector<double,
> > std::allocator<double> >&, double, searchIterInfo&, int, int, float)':
> > /home/wang75/myResearch/generic/simContSearch/optSolver.cpp:711:
> > undefined reference to `simplexInterp(std::vector<double,

>
> "undefined reference"
>
> > std::allocator<double> > const&, std::vector<std::vector<int,
> > std::allocator<int> >, std::allocator<std::vector<int,
> > std::allocator<int> > > >&, std::vector<double, std::allocator<double>
> >> &, std::vector<int, std::allocator<int> >&, int, float, int)'

> > optSolver.o(.text+0x465c): In function `fcnPart(std::vector<double,
> > std::allocator<double> > const&, std::vector<double,
> > std::allocator<double> >&, double, int, searchIterInfo&, int, int,
> > float)':
> > /home/wang75/myResearch/generic/simContSearch/optSolver.cpp:768:
> > undefined reference to `simplexInterp(std::vector<double,

>
> "undefined reference"
>
> > std::allocator<double> > const&, std::vector<std::vector<int,
> > std::allocator<int> >, std::allocator<std::vector<int,
> > std::allocator<int> > > >&, std::vector<double, std::allocator<double>
> >> &, std::vector<int, std::allocator<int> >&, int, float, int)'

> > collect2: ld returned 1 exit status
> > make: *** [runinv] Error 1

>
> > shell returned 2

>
> > ----my code ---

>
> > * * * 1 #ifndef _searchData_
> > * * * 2 #define _searchData_

>
> Generally only use ALL UPPERCASE for macro names, and never use that convention
> for other names, so as to avoid possible name collisions (macros don't respect
> scopes) *-- *this is a FAQ.
>
> I should have been less specific about underscore advice.
>
> As a rule, never use any leading underscore whatsoever, because in the global
> namespace those names are reserved for the implementation, and it's easiest to
> just never use them rather than remember where they're not reserved.
>
> > * * * 3 #include <vector>
> > * * * 4 #include <list>
> > * * * 5
> > * * * 6 typedef struct searchIterInfo {

>
> This is a C-ism, not necessary in C++. The C construct
>
> * *typedef struct { blah blah } SomeName;
>
> is, in C++, better expressed as
>
> * *struct SomeName { blah blah };
>
> > * * * 7 * * searchIterInfo ():
> > * * * 8 * * contPts(0), * * * //continuous trial points
> > * * * 9 * * contFvs(0), * * * //fv for cont points
> > * * *10 * * contFerrors(0), * //std errors for cont points
> > * * *11 * * gradients(0), * * //list of gradients
> > * * *12 * * intPts(0), * * * *//evaluated int points
> > * * *13 * * intFvs(0), * * * *//function values for int points
> > * * *14 * * intFerrors(0), * *//errors for int points
> > * * *15 * * intPtList(0), * * //the monotone list of points
> > * * *16 * * simList(0), * * * //the simplex list
> > * * *17 * * seedVals(0), * * *//the seed values
> > * * *18 * * hMtx(0) {}; * * * //the estimated hesian matrix

>
> Extraneous semicolon after right brace.
>
> Anyway you don't need to define the vector initializations because they're what
> you get by default.
>
> What you do need to initialize is what you've forgotten to initialize, namely
> the members of built-in type 'iterID' and 'sampleSize': since they're not of
> class type they don't have automatic default initialization.
>
> > * * *19
> > * * *20 * * std::vector< std::vector<double> > contPts;
> > * * *21 * * std::vector<double> * * * * * contFvs;
> > * * *22 * * std::vector<double> * * * * * contFerrors;
> > * * *23 * * std::vector< std::vector<double> > gradients;
> > * * *24 * * std::vector< std::vector<int> > * *intPts;
> > * * *25 * * std::vector<double> * * * * * intFvs;
> > * * *26 * * std::vector<double> * * * * * intFerrors;
> > * * *27 * * std::list<int> * * * * * * * *intPtList;
> > * * *28 * * std::list<int> * * * * * * * *simList;
> > * * *29 * * std::vector<int> * * * * * * *seedVals;
> > * * *30 * * std::vector< std::vector<double> > hMtx;
> > * * *31 * * int iterID; * * * * * //the sample path index
> > * * *32 * * double sampleSize; * *//the sample size for this sp

>
> Since the above doesn't communicate any purpose to me, it probably will not
> communicate any purpose to you either when you have been away from the code for
> some time. So better more self-describing names would probably be a good idea.
> It's also possible, but by no means sure, that you're doing an unnecessary
> inversion of data structure, using a struct of vectors when problem domain calls
> for a vector of structs -- generally a struct of like vectors indicate that.
>
> > * * *33 } searchIter;
> > * * *34
> > * * *35 std::vector<int> getBestIntPt(searchIter &);
> > * * *36 int searchPt(std::vector<int> &, searchIter &, double &,
> > double &);
> > * * *37 void addPt(std::vector<int> &, searchIter &, double fv, double
> > fr);
> > * * *38
> > * * *39 #endif

>
> Cheers, & hth.,
>
> - Alf
>
> - Show quoted text -


Thanks Alf,

the functions are declared and defined in simInterp.h and
simInterp.cpp respectively:
----code---

#ifndef __SIMINTERP_H__
#define __SIMINTERP_H__

void getBinary(int, vector<int> &, int);
int getDecimal(vector<int> &);
void simplexInterp(vector<double> const&, vector< vector<int> > &,
vector<double> &,
vector<int> &, int = 0, float = 1.0, int = 0);
double getInitStep(const vector<double>&, vector<double> &, int = 0,
float = 1.0, int = 0);

#endif
*****

#include "simInterp.h"
#include <vector>
#include <iostream>
#include <math.h>
void simplexInterp(vector<double> const& x, vector< vector<int> >
&simVerts, vector<double> &wts,
vector<int> &permu, int simCode, float csize, int patCode)
{
...
}

double getInitStep(const vector<double> &x, vector<double> &d, int
simCode, float csize, int bMax)
{
....
}

-----end of code---

I cannot find anything wrong here.

again, thank you very much for your kind help.

Beet
 
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++ 2 06-16-2008 11:47 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