• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

l-value specifies const object

I get the following error message while attampting to compile my code:
l-value specifies const object

In my header I declare an enum in the following manner:

SystemProperties::FlDataRate_e            currentFLrate; //this is an instance of an enum located in SystemProperties

I use the enum in the following way in my class:
    currentMidlIdlmode = midlIdlMode;

It works if i declare the enum locally in my function but i needthe varaible as a global to use across many functions.

Any ideas?
0
AviExperts
Asked:
AviExperts
1 Solution
 
jkrCommented:
Is the value a data member of a class and the method that tries to change the value declared as 'const'? That would explain the message.
0
 
AviExpertsAuthor Commented:
The value is a data member of a class but is not declared as a const.
0
 
jkrCommented:
Yes, but is the *method* where you are trying to change the value declared as 'const'? E.g.

// Example of a constant member function
class Date
{
public:
   Date( int mn, int dy, int yr );
   int getMonth() const;       // A read-only function
   void setMonth( int mn );    // A write function;
                               //    cannot be const
private:
   int month;
};

int Date::getMonth() const // <---------------------!
{
   return month;        // Doesn't modify anything
}
void Date::setMonth( int mn )
{
   month = mn;          // Modifies data member
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rstaveleyCommented:
You haven't shown us the declaration for currentMidlIdlmode. You showed currentFLrate.
0
 
AxterCommented:
Please post your code.
0
 
sambitdashCommented:
While declaring the enums make sure to declare them with public access. I guess that is what is your problem without lack of sources.

class A
{
public:
       enum e_NUM
      {
               eOne = 1,
               eTwo
      };
};

This enum can be exposed out as A::e_NUM from anywhere in the code.

Hope this solves your problem.

0
 
AviExpertsAuthor Commented:
I fixed this issue using mutables, which lets me change the value of the cariable in a constant function. similiar to const cast
0
 
jkrCommented:
So the issue was indeed that "the *method* where you are trying to change the value declared as 'const'"?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now