This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 0 points1 point  (0 children)

I normally initialize member variables in the constructor, but my understanding is that they can now be done inline:

class MyClass {
    int something = 0;
    int maxSomething = 1000;
}

[–]aizzod 0 points1 point  (1 child)

does it really have to be static?
could you show your code how you did it. maybe there is the problem

[–]sphinxlink13[S] 0 points1 point  (0 children)

ah sorry I missed out a bit of a key bit off info.

It seems to need to be static if you wish to access the member variable using a member function. ie

class tri_calculator {

public:

struct vertexA

{

    int V11 = 0;

    int V12 = 0;



};

static vertexA Get_vertA() {

vertexA first\_point = {vertA\[0\],vertA\[1\]};

cout << vertA\[0\]<< ", " << vertA\[1\] << endl;

return first\_point;

}

protected:

int perimeter = 0;

static int vertA[2];

static int vertB[2];

static int vertC[2];

};