0

the string variable named 'listt'(intentional double "t") does not appear to be declared despite it existing as a global variable.

i looked online for a solution, and all i could find were people telling me to make sure i wasn't 'using namespace std;'...which a wasn't anyway.

  #include <iostream>
#include "sally.h"
#include <string>
#include <stdlib.h>

using namespace std;

//globals

/////////////r//c
//3 = what it is you're doing, the day its happening, the time its happening
string listt[7][3];

//functions
int main()
{
    int option1;
    while(option1 != -1){
   sally obj;

    option1 = obj.menuop();
    obj.direct(option1, obj);
    }
}

header file:

#ifndef SALLY_H
#define SALLY_H


class sally
{

   public:
        sally();

        int menuop();
void direct(int a, sally obj);

void showlist();
void addlist();
void removelist();

        virtual ~sally();

    protected:

    private:

            int option1;
};

#endif // SALLY_H

body of the "addlist function"

void sally::addlist(){
    system("cls");
    string days[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
    for(int num = 0; num<7; num++){
            listt[num][0] = days[num];
       cout<<"On "<<days[num]<<" you will ";
        cout<<...<<endl;
        cin>>listt[num][1];
        system("cls");
        cout<<"On "<<days[num]<<" you will "<<listt[num][1]<<" at *insert 24 hour time here*";
    cout<<"..."endl;
    cin>>listt[num][2];
    }

}
Joe
  • 11
  • 1
  • I suspect you did not declare your `listt` global variable. So `sally::addlist` doesn't know it exists. – Eljay Aug 30 '19 at 22:23

1 Answers1

0

In your .h file you need to declare (not define) your global variable (outside the class).

extern string listt[7][3];

Every source file including this header file will see the declaration, but the definition only occurs in one module (the main source file here).

prog-fh
  • 13,492
  • 1
  • 15
  • 30