Reputation: 166
My question is about using one class's variables in another class in a different file.
I have a class in Mabbs Input.h which looks like this:
class fileParameters{
public:
static int numImageRows;
static int imageRowLength;
private:
int numRows=0;
};
int numImageRows = 640;
int imageRowLength = 480;
I would like to use the variables numImageRows and imageRowLength in a separate file called Image Centering.cpp. I am aware that I need to put it in the header Image Centering.h, which I have done.
This is the code I have in Image Centering.h:
class imageCenteringParameters{
public:
static int numImageRows;
static int imageRowLength;
private:
int imageArray[numImageRows][imageRowLength];
};
I have 2 questions:
a.) Is this the correct way to ensure I can use the variables from the class fileParameters in Mabbs Input.h in any other file? If so, is there a better/ more efficient way? If not, how would I go about fixing this, and what is good website to learn this from?
b.) It says that the fields in imageArray must have a constant size. I thought they would since they are declared in Mabbs Input.h. How would I go about fixing this, but more importantly, what does this mean?
Upvotes: 1
Views: 1711
Reputation: 6467
The inheritance relationship of two classes is declared in the derived class. Derived classes definitions use the following syntax:
class derived_class_name: public base_class_name
{ /*...*/ };
Variables definition using const type qualifier use the following syntax:
const type variable_name = initial_and_only_value;
For further reading making a constant array in C++.
Upvotes: 1