473,385 Members | 1,712 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,385 software developers and data experts.

can't link class with static methods and members

I wrote a crappy class for radian angle management. The class consists
of an array of radian values. I put all these things in a class in
which all methods are static, so I can access it anywhere in my code
(I could have made a library instead of a class).

I can't find out why g++ compiles fine, but does not link correctly
the following code. Here, I am posting my full code, .h and .cpp just
to make all things clear.

The linker output many errors. Some on them are:
/home/jf/tmp/ccEuf6Sy.o(.text+0x128): In function
`Angle::getRadValue(int)':
: undefined reference to `Angle::ra'
/home/jf/tmp/ccEuf6Sy.o(.text+0x13f): In function
`Angle::isOver(int)':
: undefined reference to `Angle::max'
/home/jf/tmp/ccEuf6Sy.o(.text+0x165): In function
`Angle::isUnder(int)':
: undefined reference to `Angle::min'

I can't figure out why, for instance, the function Angle::isOver(int)
can't find Angle::max. Angle::max was defined as static, so I think it
should be accessible, but it is not.

From what I know, the Angle::max is static, so there is only one
instance of this member, no matter how many Angle implantation there
are, so it should be accessible... isn't?

Anyone knows?

//Class definition
class Angle
{
public:

Angle();

~Angle();

static float getRadValue( int _i);

static bool isOver( int _i);
static bool isUnder( int _i);

static int increment( int _i);
static int decrement( int _i);

static int getIndiceFromDeg( int _deg);
static float ra[11];
static int min; //min indice
static int max; //max indice
};
//Class implementation
#include "angle.h"

/************************************************** **************************
* function Angle
* Default constructor
* Return: None
************************************************** **************************/
Angle::Angle() {
Angle::ra[0] = -1.308996939;
Angle::ra[1] = -1.047197551;
Angle::ra[2] = -0.785398163;
Angle::ra[3] = -0.523598775;
Angle::ra[4] = -0.261799387;
Angle::ra[5] = 0.0;
Angle::ra[6] = 0.261799387;
Angle::ra[7] = 0.523598775;
Angle::ra[8] = 0.785398163;
Angle::ra[9] = 1.047197551;
Angle::ra[10] = 1.308996939;

Angle::min = 0;
Angle::max = 10;
}

/************************************************** **************************
* function ~Angle
* This is the default destructor
* Input: None
* Return: None
************************************************** **************************/
Angle::~Angle() {
}

/************************************************** **************************
* function getRadValue
* This function returns the angle in radian from the indice
* Input: Angle indice
* Return: Angle in rad
************************************************** **************************/
float Angle::getRadValue( int _i) {
return Angle::ra[_i];
}

/************************************************** **************************
* function isOver
* This function checks if the angle indice is too high
* Input: Angle indice
* Return: Success
************************************************** **************************/
bool Angle::isOver( int _i) {
if (_i > Angle::max) {
return true;
}
return false;
}

/************************************************** **************************
* function isUnder
* This function checks if the angle indice is too low
* Input: Angle indice
* Return: Success
************************************************** **************************/
bool Angle::isUnder( int _i) {
if (_i < Angle::min) {
return true;
}
return false;
}

/************************************************** **************************
* function increment
* This function moves to the next angle, upper
* Input: Angle indice
* Return: New angle indice
************************************************** **************************/
int Angle::increment( int _i) {
if (Angle::isOver(_i + 1)) {
return _i;
}
return (_i + 1);
}

/************************************************** **************************
* function decrement
* This function moves to the next angle, lower
* Input: Angle indice
* Return: New angle indice
************************************************** **************************/
int Angle::decrement( int _i) {
if (Angle::isUnder(_i - 1)) {
return _i;
}
return (_i - 1);
}

/************************************************** **************************
* function getIndiceFromDeg
* This function returns the angle indice from its degree value
* Input: Angle in degree
* Return: Angle indice
************************************************** **************************/
int Angle::getIndiceFromDeg( int _deg) {
switch (_deg) {
case -75: return 0;
break;
case -60: return 1;
break;
case -45: return 2;
break;
case -30: return 3;
break;
case -15: return 4;
break;
case 0: return 5;
break;
case 15: return 6;
break;
case 30: return 7;
break;
case 45: return 8;
break;
case 60: return 9;
break;
case 75: return 10;
break;
}
}
Jul 22 '05 #1
1 1822
Jean-Francois Brault wrote:

The declaration in a class of a static data member doesn't count as a
definition. There has to be a separate definition in exactly one
translation unit (in your case, the same file where you define the
member functions of Angle), like this:

float Angle::ra [10];
int Angle::min;
int Angle::max;

--
Regards,
Buster.
Jul 22 '05 #2

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

Similar topics

1
by: Phil Powell | last post by:
Consider this: class ActionHandler { ...
0
by: Steve Menard | last post by:
As par of JPype, I find that I have to brifge Java static members into class attributes. I am using a metaclass to dynamically create a Python class for every Java type encountered. Instance...
5
by: Jon Paugh | last post by:
Is there a standard for where to put the different categories of code in a class file? For example, after the class declaration, normally I put class variables, then constuctor, then private...
6
by: lovecreatesbeauty | last post by:
Hello Experts, Why static data members can be declared as the type of class which it belongs to? Inside a class, non-static data members such as pointers and references can be declared as...
5
by: A_StClaire_ | last post by:
annoying one. can anyone spot the issue? it appears communityCards can't be accessed via my static function but I don't know why... Game.h: #pragma once #include <vector> #include...
15
by: ad | last post by:
We can define a static member in a class. But can we define a static class, so that all members are static?
7
by: Atul Malaviya | last post by:
>From a design/usability perspective. When will one use a singleton pattern and when a class with purely static members? What are the pros and cons? I have inherited a code base which is full...
11
by: Raja Chandrasekaran | last post by:
Hai folks, I have a question to get exact answer from you people. My question is How Static class is differ from instance class and If you use static class in ASP.NET, ll it affect speed or...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.