I have the main function and a class, I'am trying to use an int that is in that other class in main.
main.cpp
#include <iostream>
#include "main.hpp"
using namespace std;
int main()
{
cout << MainInt::x << endl;
return 0;
}
main.hpp
class MainInt
{
public:
MainInt();
int x;
};
MainInt::MainInt()
{
x = 1;
}
The way I am doing it currently doesn't feel right. I feel like cout << MainInt::x << endl;
is just calling the variable x.
Currently I get
error: invalid use of non-static data member 'x'
What I need is to call x which is a non-static variable in MainInt such that I can output the value of x on the console. How do I go about doing that?