why is the var out of scope?

Hi

i have a simple class, but he tells me that _bluePin, _greenPin and _redPin are out of scope(?) in the light.cpp in analogWrite(_bluePin, blue);

light.h

#ifndef light_h
#define light_h

#include "Arduino.h"



class light {
    
  public:   
    light(int redPin, int greenPin, int bluePin);    
    void setColor(int red, int green, int blue);
    
  private:
    
    int _redPin;
    int _greenPin;
    int _bluePin;
};

#endif

light.cpp

/*
  light.cpp 
*/

#include "Arduino.h"
#include "light.h"

light::light(int r, int g, int b) {
    _redPin = r;
    _greenPin = g;
    _bluePin = b; 
}

 void setColor(int red, int green, int blue) {
    #ifdef COMMON_ANODE
        red = 255 - red;
        green = 255 - green;
        blue = 255 - blue;
    #endif
    
    analogWrite(_redPin, red);
    analogWrite(_greenPin, green);
    analogWrite(_bluePin, blue); 
    
 }

why is that?

 void setColor(int red, int green, int blue) {

Missing scope resolution operator ::

AWOL:

 void setColor(int red, int green, int blue) {

Missing scope resolution operator ::

sorry, can you explain?

You defined the pin numbers as private members of the class "light", which means that they are out of scope to anything that is not a member of "light".
The constructor "light::light" (hint) is a member of "light", but "setColor" is not.

Is setColor a method of your class? how do you declare a method (member functions of a class)?

AWOL:
You defined the pin numbers as private members of the class "light", which means that they are out of scope to anything that is not a member of "light".
The constructor "light::light" (hint) is a member of "light", but "setColor" is not.

aaaaaaaahh.. so you mean it should be

  void light::setColor(int red, int green, int blue) {

??

Is setColor a method of your class? how do you declare a method (member functions of a class)?

i though so (??) oO ..

class light {
public:   
    light(int redPin, int greenPin, int bluePin);    
    void setColor(int red, int green, int blue);
   ...

..what do you mean?

aaaaaaaahh.. so you mean it should be

Yup - hence the earlier comment about the scope resolution operator.

I meant to help with the hint of AWOL in #1 but was slow to type so more info arrived in between

hey cool :slight_smile: .. big thanks to both :slight_smile: