Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 9th, 2008, 03:45 PM
Jim
Guest
 
Posts: n/a
Default using static arrays

Hello,
I have a very simple object, freqoffset which I'm trying to use as
members of a static array of in another class
class freqoffset
{
public:
freqoffset():offset(0),strength(0){};
int set(double offset,double strength);
double getOff() const{return offset;};
double getStr() const{return strength;};
private:
double offset,strength;
};

class nh3fitting
{
private:
static const int sn1=18;
static const int sn2=21;
static freqoffset s1[sn1];
static freqoffset s2[sn2];
public:
nh3fitting(double cr, double cd, int n, double sd); //generates an
array and populates it with x values
static int loadArrays();
};

int nh3fitting::loadArrays()
{
s1[0].set( -1.56893, 0.0741);
s1[1].set(-1.526658 , 0.1481);
s1[2].set(-0.623335 , 0.0926);
s1[3].set( -0.590375, 0.1667);
s1[4].set(-0.581021, 0.0185);
s1[5].set(-0.036389 , 0.0370);
s1[6].set(-0.025453 , 0.0185);
s1[7].set(-0.024583, 0.0333);
s1[8].set(-0.015196, 0.3);
s1[9].set(0.005941, 0.0185);
s1[10].set(0.010463, 0.4667);
s1[11].set(0.016835, 0.0926);
s1[12].set(0.019832, 0.0333);
s1[13].set(0.571708, 0.0926);
s1[14].set(0.582719, 0.0185);
s1[15].set(0.617689 , 0.1667);
s1[16].set(1.53405, 0.0741);
s1[17].set(1.545159, 0.1481);

s2[0].set(-2.099033 ,0.0042 );
s2[1].set(-2.058267 , 0.0377);
s2[2].set( -2.053459, 0.0209);
s2[3].set(-1.297087, 0.0372);
s2[4].set(-1.296079,0.026 );
s2[5].set(-1.255384, 0.0019);
s2[6].set(-0.044498, 0.0209);
s2[7].set(-0.041806, 0.0106);
s2[8].set(-0.041456, 0.0116);
s2[9].set(-0.001031, 0.1465);
s2[10].set(0.000309, 0.4997);
s2[11].set(0.001054, 0.2674);
s2[12].set(0.039736, 0.0106);
s2[13].set(0.042055, 0.0116);
s2[14].set(0.046621 , 0.0209);
s2[15].set(1.254559, 0.0019);
s2[16].set(1.295363, 0.026);
s2[17].set(1.296295, 0.0377);
s2[18].set(2.053476, 0.0209);
s2[19].set(2.058256, 0.0377);
s2[20].set(2.099022, 0.0042);

return 0;
}

Unfortunately I get a linker error when trying to do this,
g++ -I/usr/include/gsl/ -L/usr/lib/ -c nh3fit.cpp
g++ -I/usr/include/gsl/ -L/usr/lib/ -lgsl -lgslcblas nh3fit.o -o
nh3fit
nh3fit.o: In function `nh3fitting::loadArrays()':
nh3fit.cpp:(.text+0xb7): undefined reference to `nh3fitting::s1'
nh3fit.cpp:(.text+0xd9): undefined reference to `nh3fitting::s1'
nh3fit.cpp:(.text+0xfb): undefined reference to `nh3fitting::s1'
nh3fit.cpp:(.text+0x11d): undefined reference to `nh3fitting::s1'
nh3fit.cpp:(.text+0x13f): undefined reference to `nh3fitting::s1'

and so on for both s1 and s2. Does anyone have any suggestions?

Thanks in advance,
James
  #2  
Old July 9th, 2008, 03:55 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: using static arrays

Jim wrote:
Quote:
Hello,
I have a very simple object, freqoffset which I'm trying to use as
members of a static array of in another class
class freqoffset
{
public:
freqoffset():offset(0),strength(0){};
int set(double offset,double strength);
double getOff() const{return offset;};
double getStr() const{return strength;};
private:
double offset,strength;
};
>
class nh3fitting
{
private:
static const int sn1=18;
static const int sn2=21;
static freqoffset s1[sn1];
static freqoffset s2[sn2];
Where are those _defined_?
Quote:
public:
nh3fitting(double cr, double cd, int n, double sd); //generates an
array and populates it with x values
static int loadArrays();
};
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
  #3  
Old July 9th, 2008, 03:55 PM
Mike Wahler
Guest
 
Posts: n/a
Default Re: using static arrays


"Jim" <ja@astro.livjm.ac.ukwrote in message
news:2dec5e75-fd38-4dc0-a323-1d249810a0d3@27g2000hsf.googlegroups.com...
Quote:
Hello,
I have a very simple object, freqoffset which I'm trying to use as
members of a static array of in another class
class freqoffset
{
public:
freqoffset():offset(0),strength(0){};
int set(double offset,double strength);
When I add the function body for 'set()', the
error goes away.

-Mike



  #4  
Old July 9th, 2008, 04:05 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: using static arrays

Mike Wahler wrote:
Quote:
"Jim" <ja@astro.livjm.ac.ukwrote in message
news:2dec5e75-fd38-4dc0-a323-1d249810a0d3@27g2000hsf.googlegroups.com...
Quote:
>Hello,
>I have a very simple object, freqoffset which I'm trying to use as
>members of a static array of in another class
>class freqoffset
>{
>public:
>freqoffset():offset(0),strength(0){};
>int set(double offset,double strength);
>
When I add the function body for 'set()', the
error goes away.
Really?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
  #5  
Old July 9th, 2008, 06:25 PM
Juha Nieminen
Guest
 
Posts: n/a
Default Re: using static arrays

Jim wrote:
Quote:
static freqoffset s1[sn1];
static freqoffset s2[sn2];
You declare two static arrays here, but you don't define
("instantiate") them anywhere. In other words, you are telling the
compiler "these arrays exist somewhere" (which is one thing "static"
does), however, you never actually create those arrays anywhere. Thus
the linker cannot find them and complains.

You have to put these somewhere:

freqoffset nh3fitting::s1[nh3fitting::sn1];
freqoffset nh3fitting::s2[nh3fitting::sn2];
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.