I am trying to understand the usage of private const in the class. My understanding is that private const is used to make something constant within the class and static to have one copy.
Initially, my code was using pi and it's data type was float. So, I tried changing the float to int because I read const static is only allowed for int types within class.
#include
class MyExample
{
private:
static const int x;
};
int main(void)
{
int const MyExample::x = 3;
std::cout<<"x value is "<<MyExample::x<<std::endl;
return 0;
}
compiling -
$g++ -std=c++14 test.cpp
test.cpp: In function ‘int main()’:
test.cpp:12:27: error: qualified-id in declaration before ‘=’ token
int const MyExample::x = 3;
I know that moving the line " int const MyExample::x = 3;" from main() to outside, removes error if I remove private also.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)