Go Down

Topic: What am doing wrong here with my class? (Read 1 time) previous topic - next topic

Nick Gammon

Yes, but the point of classes is they have objects (instances of that class).

This is purely to avoid naming clutter is it? You might want to consider using a namespace.

scswift

I'd never heard of namespaces.  That looks like the sort of thing I was looking for, but I gotta say, C++ seems pretty ridiculous to me.  You've got structs, classes, and now namespaces, and they all seem to (mostly) duplicate the functionality of one another. 

Nick Gammon


scswift

Well, to reduce clutter like you said.  Though I had also planned to make some of the variables private and only accessible to the functions in the class.  Which it seems I can't do with name spaces.  But I guess that doesn't really matter, I mean I'm not making a huge application here and I'm not worried about accessing something I shouldn't somewhere I shouldn't. I was just going to do that because it's good practice. 

So I guess I'll use a namespace instead and forget the whole private data thing.

So with namespaces I don't have to redeclare those variables in the namespace outside of it eh?  Or use static? 

I'm getting another error now though:

Code: [Select]

namespace LED {
   
    static int MODULES;   // Number of LED modules connected.  Defined in config.txt.
 
    static byte * data;    // LED data is stored as a string of 12 bit LED values.  There are 3 bytes for every two LEDs.  We store it this way because the data does not need to be altered when we are shifting it out to the TLC5947s.  Modifying the data with bit shifts would be very expensive and there is a lot of data to move.
    static byte * scale;   // Scaling factor for LED brightness.  Used when say, you want to be able to adjust the brightness of the powercell without changing all the code that assumes the max desired brightness is 1.0.  Value stored here is scaling_factor*255, where scaling factor is 0..1.

    void set(int, float, float); 
    float get(int);
   
};


"Namespace LED {} redeclared as different type of symbol."

scswift

Eh, nevermind that error, it's because LED is defined in the arduino pin definitions.   Not sure why that didn't throw an error before.

Go Up