in Education by
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)

1 Answer

0 votes
by
I have the same problem, but when I put static member initialization out of main function, the problem is solved, like this: int const MyExample::x = 3; int main(){...}

Related questions

0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    What does a compiler do? It translates source code into activities (which may comprise groups of machine instructions) ... only enables the programmer to edit the program files....
asked May 1, 2021 in Education by JackTerrance
0 votes
    A compiler in computing means- (a) A programmer. (b) A person who compiles source program. (c) Keypunch ... program into object program Select the correct answer from above options...
asked Dec 11, 2021 in Education by JackTerrance
0 votes
    I've seen examples that allow you to create a manipulator that inserts delimiters but none of those manipulators are sticky. That is, ... . I want to be able to do this: std::cout...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    It is common practice to declare stack variables (variables allocated on the excecuting stack rather than dynamically ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    I have defined an interface in C++, i.e. a class containing only pure virtual functions. I want ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
...