I have a main method in my main.cpp that I would like to display the value of a constant int I have declared.
I added a DeclareConstant class.
Here is my DelcareConstant.h
#pragma once
class DeclareConstant
{
public:
const int x;
Part1(void);
Part1(int x);
~Part1(void);
double getX(){return x;}
};
And source
#include "Part1.h"
Part1::Part1() : x(55){
}
How can I access X so I can display it in my main method? I need to check if I’m even initializing it correctly.
You can access
xthrough getter functiongetX(), for example:Or
However, you should define your getX like this:
And please hide your class member.