0

I'm new to C++ at university; because the class is going to pick up pace fast, I'm going to implement class functions and header files etc but we're expected to teach ourselves.

I'm getting the following 3 errors:

MagicSquareAlg2.cpp:145:27: error: expected primary-expression before `.' token
   diagLength = Diagnostics.userInput(*input, &inputFlag);
                       ^
MagicSquareAlg2.cpp:148:49: error: expected primary-expression before `.' token
  vector< vector<int> > magicSquare = MagicSquare.matrixBuild(diagLength);
                                             ^
MagicSquareAlg2.cpp:149:13: error: expected unqualified-id before `.' token
  Diagnostics.summary(magicSquare, diagLength);

Here is my code. Could someone please offer simple hints as to what I'm doing wrong (enough so that I don't have to cite)? The online tutorials I'm trying haven't helped too much.

class Diagnostics {
    public:
        vector< vector<int> > magicSquare;
        string diagLengthPrep;
        bool* inputFlag;
        int diagLength;

        int  userInput(string diagLengthPrep, bool* inputFlag);
        void summary(vector< vector<int> > magicSquare, int diagLength);
};

int Diagnostics::userInput(string diagLengthPrep, bool* inputFlag) {
    //Code
}

void Diagnostics::summary(vector< vector<int> > magicSquare, int diagLength) {
    //Code
}

class MagicSquare {
    public:
        int  diagLength;

        vector< vector<int> > matrixBuild(int diagLength);
};

vector< vector<int> > MagicSquare::matrixBuild(int diagLength) {
    //Code
}

void session(string* input, bool inputFlag) {
    int diagLength;

    while (inputFlag == true) {
        //Code

        diagLength = Diagnostics.userInput(*input, &inputFlag);
    }

    vector< vector<int> > magicSquare = MagicSquare.matrixBuild(diagLength);
    Diagnostics.summary(magicSquare, diagLength);
}

int main() {
    //Code
}
user3834916
  • 143
  • 1
  • 11
  • 3
    [The Definitive C++ Book Guide and List.](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) Learn the difference between classes and *instances* (objects) of classes. – Some programmer dude Feb 13 '15 at 08:43

1 Answers1

0

You are trying to call non-static member functions without an instance. To fix this, construct instances of your classes and call the functions on them:

void session(string* input, bool inputFlag) {
    int diagLength;
    Diagnostics diags; //here
    while (inputFlag == true) {
        //Code

        diagLength = diags.userInput(*input, &inputFlag);
    }

    MagicSquare ms; //here
    vector< vector<int> > magicSquare = ms.matrixBuild(diagLength);
    diags.summary(magicSquare, diagLength);
}
TartanLlama
  • 63,752
  • 13
  • 157
  • 193