user3291423 user3291423 - 1 month ago 20
C++ Question

Accessing a struct inside of a private class C++

I am lost in trying to figure out how to access this struct that is inside of the private part of the class. I I would need the code to stay as a struct if that is possible.
Thanks very much for the help.

const int MAX_CHAR = 101;
const int NAME_COURSE_WIDTH = 20;
const int DESCRIPTION_WIDTH = 40;
const int DUE_DATE_WIDTH = 20;
const int COURSE_ENTRY_CAPACITY = 100;

class Task
{
private:
struct CourseEntry
{
char course[MAX_CHAR];
char description[MAX_CHAR];
char dueDate[MAX_CHAR];
} course;
public:


void displayMenu();
char readInCommand();
void processCommand(char command, CourseEntry list[], int& listSize);
void readInEntry(CourseEntry& anEntry);
void readInCourse(char course[]);

//database related functions
void displayAll(const CourseEntry list[], int listsize);
void addEntry(const CourseEntry& anEntry, CourseEntry list[], int& listSize);
bool searchEntry(const char course[], CourseEntry& match, const CourseEntry list[], int listSize);

void loadCourseEntry(const char fileName[], CourseEntry list[], int& listSize);
void saveCourseEntry(const char fileName[], const CourseEntry list[], int listSize);

//standard input tools
int readInt(const char prompt[]);
void readString (const char prompt[], char inputStr[], int maxChar);
};

Answer

You should move the definition of the struct outside the class, and just keep the variable private:

struct CourseEntry
{
    char course[MAX_CHAR];
    char description[MAX_CHAR];
    char dueDate[MAX_CHAR];
}

class Task {
    private:
       CourseEntry course;

    public:

        ...
}