<Variablename> does not name a type

OK, I have a bit if a confusing issue here.. The project is a little big to all post here, so i'll post the relevant parts...

The following doesn't work if I have it outside the Setup or Loop routines, it does work inside them... Problem is I'd like to initialize them as global variables

Is there something I'm doing wrong or is it just not possible? Would I have to have the class constructor accept all the variables and set them all that way? (get a little long when you have a lot of them);

MyVar Blah; //Myvar is a class I've defined.. code later

float blahSmoothing = Blah.Smoothing; // This works
Blah.Smoothing = 1.0f;                     //This fails, "Blah does not name a type"

Here's the header file MyVar.h

#ifndef MyVar_h
#define MyVar_h

#include "Arduino.h"


class MyVar {
  public:
    MyVar();
    int EEPROMAddress;
    float Smoothing;
    float Response;
    float MinChange;
    float MaxChange;
    float MaxValue;
    float MinValue;
    int Multiplier;

    float Value();
    float RecurvedValue();
    void UpdateValue(float NewValue);


  private:
    float Storage;
    float GetSmoothedValue(float Newvalue, float Oldvalue, float smoothing, float Minchange, float Maxchange);
    float mapf(float value, float oldlow, float oldhigh, float newlow, float newhigh);
};

#endif

Here's the MyVar.cpp file

#include "Arduino.h"
#include "MyVar.h"

int EEPROMAddress;
float Smoothing;
float Response;
float MinChange;
float MaxChange;
float MaxValue;
float MinValue;
float Storage;
int Multiplier;

MyVar::MyVar(){
   Smoothing = 1;
   Response = 1;
   MinChange = 1;
   MaxChange = 1024;
   MinValue = 0;
   MaxValue = 1024;
   Storage = 0;
}


//more other functions that were defined in the header

Thanks

From the cpp file:

int EEPROMAddress;
float Smoothing;
float Response;
float MinChange;
float MaxChange;
float MaxValue;
float MinValue;
float Storage;
int Multiplier;

What is this crap? Why are you declaring all these global variables that are not part of the class, but have the same name as class members?

Post ALL of your code - not just what you think we need to see.

Attached is the entire project... At this point I'm just trying to figure out what works as far as layout, and the flow of things is yet to be determined

I'm still getting the grasp of how the header and cpp files interact, I have now commented out all the extra variables you mentioned and avoided the duplication.

Basics_v1.0-150601b.zip (13.2 KB)

Your code needs to be inside setup( ) or loop( ) or some other function.

You can't have regular executable statements just sitting around anywhere in your source code file, they need to be inside the functions, or inside the class definitions.

float blahSmoothing = Blah.Smoothing; // This works
Blah.Smoothing = 1.0f; //This fails, "Blah does not name a type"

The first line here works, because it is the declaration, with initialization, of your variable blahSmoothing, which will have global scope in that source code file, because it apparently is declared outside any of your functions.

The second line doesn't work, because it is a regular assignment statement ( not a declaration ), and therefore it has to be inside a function somewhere.

All those variables which you declare at the top of your MyVar.cpp file would seem to be pointless, and probably wrong.

It's fine to have global variables, if they are managed properly. But to consider them as associated with a particular class, is not in the spirit of OO. Even if you can somehow force them to interact. Generally, C++ was designed to support OO, but not enforce it. So you can't assume that you're doing something correctly, just because it's permitted.

Thanks.. I am putting all the initialization in it's proper place now..., and the variable declarations at the beginning of the cpp file are gone too

This has been a bit of a steep learning curve, and the project is certainly an ambitious one with my C experience...

Rx7man:
The following doesn't work if I have it outside the Setup or Loop routines, it does work inside them... Problem is I'd like to initialize them as global variables

Initialise them in setup(), which works. That's what setup() is for.

Because of the forcasted size of this project, I have a call to another function in setup where it all happens.. I'm trying very hard to not write spaghetti code and the jury is out on that

Thanks for the help... I do have another little issue with drastically varying loop times but I'll work on it myself a while first.