Thread: Assigning a values to a class field

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    92

    Assigning a values to a class field

    Code:
    class RemoteController
    {  
      public:
        static const int numKey[];
        static const int controlKey[];
        boolean isKeyFound;
        int getNumKeyPressed(int);
    };
    
    
    static const int RemoteController::numKey[10] = { 0xFF4AB5, 0xFF6897, 0xFF9867, 0xFFB04F
                         ,0xFF30CF, 0xFF18E7, 0xFF7A85, 0xFF10EF
                         ,0xFF38C7, 0xFF5AA5
                       };
    static const int RemoteController::controlKey[5] = { 0xFF629D, 0xFFA857, 0xFFC23D , 0xFF22DD,
                            0xFF02FD
                          };
    
    
    
    
    
    
    int RemoteController::getNumKeyPressed(int keyPressed)
    {  
      isKeyFound = 0;
      for( int i = 0; i < 10; i++){
       
            if( /*results.value*/ keyPressed == numKey[i])
            {
              isKeyFound = true;
              Serial.println("Key found");
              return i;
            }
      }
        if( isKeyFound = false)
          Serial.println("Couldn't find the key, wrong key pressed!");
    }
    I get error : "'static' may not be used when defining (as opposed to declaring) a static data member [-fpermissive]"

    What is the right way of assigning values to a array field?
    This is just the part of my microcontroller code that is why there is no main function.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,686
    Just remove the word 'static' from lines 11 and 15.

    You should make 5 and 10 constants as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    92
    Quote Originally Posted by Salem View Post
    Just remove the word 'static' from lines 11 and 15.

    You should make 5 and 10 constants as well.
    Big thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assigning a value to a static field
    By ZeroesAndOnes in forum C++ Programming
    Replies: 6
    Last Post: 08-01-2016, 03:12 PM
  2. Replies: 1
    Last Post: 05-31-2009, 04:02 PM
  3. Question about assigning values
    By DCMann2 in forum C Programming
    Replies: 7
    Last Post: 04-18-2008, 07:36 AM
  4. assigning values
    By alex_6169 in forum C Programming
    Replies: 7
    Last Post: 05-15-2006, 02:16 AM
  5. Need help comparing db field values in c++
    By misha in forum C++ Programming
    Replies: 18
    Last Post: 07-09-2003, 09:37 AM

Tags for this Thread