A question on classes

I am writing a menu driven program and I want to use classes to display the different sections of the program. The problem that I am encountering is when I am writing the header for the class my private members are giving an error that says incomplete type not allowed. Is this because its return type is void? should I be using a string type instead? The class members will only be using cout statements. Also would it be better to just use a function instead of a class?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #pragma once
#include <string>
#include <iostream>
using namespace std;

class study {
private:
	void secOne;
	void secTwo;
	void secThree;
public:
	void getSecOne();
	void getSecTwo();
	void getSecThree();
};
Hi,

Is this because its return type is void?


Yes.

should I be using a string type instead?


No.

The class members will only be using cout statements. Also would it be better to just use a function instead of a class?


Yes. The main purpose of a class is to have some member data, and member functions that deal with that data. If the your output data via std::cout is always the same, there is no need for a class.

However, if you are going to have std::strings which change, then you could have a class, but use better names for the variables and functions:

study.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>

using namespace std;

class study {
private:
	std::string SectionOneText;
	std::string SectionTwoText;
	std::string SectionThreeText;
public:
     void PrintSectionOneText();
     void PrintSectionTwoText();
     void PrintSectionThreeText();
};


study.hpp

1
2
3
4
5
void study::PrintSectionOneText() {
   std::cout << "Section One Text\n";
}

// ... other function definitions 


Even better would be to have a std::vector of the std::strings:

1
2
3
4
5
6
7
#include <string>
#include <vector>

// ....

private:
  std::vector<std::string> SectionTexts;


You should also have constructors for your class.

Have a read of this:

http://www.cplusplus.com/doc/tutorial/classes/

Search about why using namespace std is bad.

Thank you so much TheIdeasMan for the information. I am new to this and my class is accelerated so I am having trouble keeping up. I updated my program using your input and everything is good unfortunately my professor wants me to continue using namespace std because it is an introductory class but I will keep that in mind for the future. also I did not even see the tutorials section thank you for pointing that out to me I will make that my first stop when I have questions from now on
Topic archived. No new replies allowed.