3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by rubberman
0

Classes are derived datatypes.
When you want to create your own datatype, with its own methods/functions for working with it, then one should implement classes.
Example : Suppose you are given a code to create a student dataype and record there information, this is a basic code while implementing class.

class student 
{
    int roll;
    char name[25];
    char add [25];
    char city[90];

    public:

    void getdata()
    {
        cout<<"\n enter the student roll no.";
        cin>>roll;
        cout<<"\n enter the student name";
        cin>>name;
        cout<<"\n enter ther student address";
        cin>>add;
        cout<<"\n enter the student city";
        cin>>city;
    }
    void putdata()
    {
        cout<,"\n the student roll no:"<<roll;
        cout<<"\n the student name:"<<name;
        cout<<"\n the student coty:"<<city;
    }
};
0

As shown by np_complete, you can implement methods of a class inline, in which case you don't need to compile them as a separate translation unit. They are truly inline code, implemented in each translation unit that uses them.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.