Question about Classes and Structure

This is a discussion on Question about Classes and Structure within the C++ Programming forums, part of the General Programming Boards category; Hi,
I am having problem with Classes, I have made a small program of Classes which is :
Code:
main()
...

I have made this small program of Class, I have also defined the data members of the data but when I compile the program, it gives me error messege.Am I geting this error because the class is defined private?
How can I make the data members in (2) to access the Class in (1)?

The entire purpose of declaring members private (preceding them by the private keyword and a colon in the class definition, as you have done) is to make them inaccessible to arbitrary code - hence the error messages.

The only code that is allowed to access a private member of class Student is a member function of class Student or friends. If a function is declared as a friend, then that function can access private members. If another class is declared as a friend, then all member functions of that class can access private members.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

There's a lot wrong with your code. Take a look at this. Lots of the bugs are fixed, and I inserted some comments about various parts of the code...

Code:

#include <iostream>
class Student {
public:
Student(){}
private:
int age;
int grade; // should this be char?
char name;
// Should probably be char name[LENGTH] where LENGTH
// is the length of the string you want defined, or seeing how
// you're using C++ you might as well use std::string name
//after #including <string>
char address; // Same comments as per name
};
// Main returns int
int main() {
Student myStudent;
// Well, as it is defined this is all you can do with this :-) You need to add some functionality
return 0;
}

However, if all you want is to store age, grade, name and address you might consider using a struct instead of a class. As it is your class doesn't do anything. You'll need to define and implement functionality, like getters/setters if you want.

If you define the class inside a function then it is only available for use inside the function you've defined it in. By making the definition global, all functions that need to make use of the class can do so. The individual instances of said class should be kept as local as possible but the definition should be global.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens

To protect yourself from code changes. If the means of getting a value changes in the future (say that you suddenly start storing your data in a database), then you only have to change the getter function. The rest of your code that uses the getter function will keep on working like before.
Otherwise you have to change every place that gets that value.