Base class has two public data members. How can i derive a
new class with one datamember as public and another data
member as private?.
Answer Posted / deepak sharma
class base
{
public:
base(int d1 = 5, int d2 = 6) : data1(d1), data2(d2)
{ }
int data1, data2;
};
class der:public base
{
private:
using base::data1; //Making data1 of class base
private, explicitliy,
//you can make member functions private or
protected this way
};
int main(int argc, char* argv[])
{
der obj1;
cout<<obj1.data1<<endl; //Error : 'data1' : cannot
access private member declared in class 'der'
cout<<obj1.data2<<endl; //Works fine
return 0;
}
| Is This Answer Correct ? | 9 Yes | 0 No |
Post New Answer View All Answers
What is abstraction with example?
What is abstraction oop?
What does sksksk mean in text slang?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
write a program to find 2^n+1 ?
Can bst contain duplicates?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
What are the three main types of variables?
What is oops concept with example?
What type of loop is a for loop?
How is class defined?
Can abstract class have normal methods?
What are the 4 main oop principles?
This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line preceded by a line number. Print the line number right-adjusted in a field of 3 spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior if the line is too long (i.e., wrap or truncate). A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.
Why do pointers exist?