Click to See Complete Forum and Search --> : Please help - horribly stuck


baxybaxy
December 7th, 2006, 05:13 AM
Hi all,

Disclosure- i'm a beginner! (this will become apparent)

I am having horrible problems trying to get to grips with namespaces, #include statements etc.... I cannot get the basic rules right on how to arrange the code so that it compiles correctly every time

Can anyone point me in the right direction for an article on this, or perhaps help on the specific example below:

I have a static function :

static void Metric_set_rollingmeanValue(int phase, int metricnumber, int location, double value, int count)

{
....

}
-> resides in my code header staticData.h -> deals with a small number of global variables

also in staticData.h, I have a enumerator
public enum metricnumber {

leadtime_metricnumber,
order_volIntake,order_volShipped,order_volFilled,
order_numordIntake,order_numordShipped,order_numordFilled,
order_growth......

from my main form, Form1, I am able to reference this data ok
for example:

Metric_set_rollingmeanValue(phase,leadtime_metricnumber,location, leadtime, countdata[phase][location]);

However, when I try and call the same function from another class
(my Order class), I get errors like:

Error 3 error C3861: 'Metric_set_relValue': identifier not found
Error 5 error C2365: 'Metric_set_relValue' : redefinition; previous definition was 'formerly unknown identifier'
Error 1 error C2653: 'metricnumber' : is not a class or namespace name

Does this hold any clues for what I am doing wrong?

Thank you very much in advance for any help

darwen
December 7th, 2006, 09:39 AM
(1) When calling static methods you need to give the class in which it resides as per the following :


__gc class MyClass
{
public:
static public void DoSomething() { };
} ;

__gc class MyOtherClass
{
public:
static public void CallMyClass()
{
MyClass::DoSomething();
}
} ;


Second you need to #include the .h at the top of the file wherever you're using it. Otherwise that file won't know about the class.

Darwen.

baxybaxy
December 7th, 2006, 11:44 AM
Darwen

thanks for your post

using your example, my DoSomething functiion is not actually sitting in a class - it is just a function 'floating' on a header file.
is this an issue?

what is weird is that i CAN call the function from Form1.h (which is a class- inherited from windows form), but NOT from Order (which is my own class, sitting on dynamicData.h)

i suspect that the issue is therefore something to do with the #include statements

Form1 currently includes staticData and dynamicData
staticData includes dynamicData
but dynamicData does not include staticData

i guess this would explain why i cannot call the functions or enum on static using a class defined on dynamic

however, if i include staticData on dynamic, all hell breaks loose and i get loads of other erros