Do you need to implement a class in order for an object to access the class's functions/methods?
When should you implement a class? When shouldn't you?

Recommended Answers

All 2 Replies

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;
    }
};

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.