Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi!!!!,I’m a new in the world of pr

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi!!!!,I’m a new in the world of programming(C++)…I want to know about..what the meaning and the function of :-

Class base{

1)Private
2)public:
void getdata();
void display();

3)class derivedB:public base and what the different with
symbol ::
4)and the meaning in void main()
{
base*ptr;
derivedB object;
ptr=&object;
ptr->getdata();
ptr->display();
getch();

This is my program:-


#include<iostream.h>
#include<conio.h>



class base{
private:

int x;
int y;



public:
void getdata();
void display();


};

class derivedB:public base{

private:
int rollno;
char name[20];


public:
void getdata();
void displaydata();

};

void base::getdata()

{

cout<<
 
Hi Visitor

ok

there are 3 categories of access to a class
1 public the data members and functions can be accessed by any external part of the program

2 private these members can only be accessed by member functions of the class (also other class member functions that have been declared as &quot;friend&quot; classes of functions

3 protected used for inheritence


2)public:
void getdata();
void display();

this means that the member functions can be called by external non member function within your code


3 :: is the scope resolution operator in other words if you have a derived class and a base class with the same function names this allows you to specify which class function you are calling base or derived

4
base*ptr; // pointer to base class
derivedB object; // an instance of a derivedb object
ptr=&object; // reassiging ptr tp point to the instance
//object
ptr->getdata(); // now calls derived member function
ptr->display(); // again calls derived member function
getch(); // ugly not a c++ method use istream but
// you need to learn more first ;-)


void base::getdata() // scope resolution you intend to call the base class member function...

hang in it will become clear, join the forum and enjoy

HTH
Robert


[sig][/sig]
 
Thank u very much for your explanation!!!! Robertd...i hope u can guide me to be agood programming again..and i hope we can be a member for the fortune
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top