TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
-------
NA
213
6.9k
which way to access a base class function or variable
Apr 19 2020 2:39 AM
I m a student. Today I Give the Interview and tell me something new about inheritance
I said the derived class can not access the base class property or field because below program prove that is why I tell the derived class can not access the base class property or field:
using
namespace
std;
#include<iostream>
class
baseclass
{
public
:
int
a;
baseclass()
{
std::cout <<
"baseclass\n"
;
}
};
class
deriveclass:
public
baseclass
{
public
:
deriveclass()
{
std::cout <<
"derived class\n"
;
}
};
int
main()
{
baseclass * a=
new
baseclass();
//ok
deriveclass * b=
new
deriveclass();
//ok
baseclass * aa=
new
deriveclass();
//ok
deriveclass * bb=
new
baseclass();
//not ok
return
0;
}
Link:https://onlinegdb.com/SyfhRDF_U
error:
main.cpp: In function ‘int main()’: main.cpp:30:36: error: invalid conversion from ‘baseclass*’ to ‘deriveclass*’ [-fpermissive] deriveclass * bb=new baseclass(); //not ok
then Interviewer tells me which way to access the base class function or variable?
help?
Reply
Answers (
3
)
hi Team, the below pic shows date which i am gett
Get Date on query string in asp.net c#