Applying “using” keyword on C++ pure virtual function












8














The Class B is overriding the pure Virtual Function "print()" of class A. Class C is inheriting Class B as well as having a "using A::print" statement.
Now why Class C is not an abstract class?



class A {
public :
virtual void print() =0;
};

class B:public A {
public:
void print();
};

void B :: print() {

cout << "nClass B print ()";
}

class C : public B {

public:
using A::print;
};

void funca (A *a) {

// a->print(1);
}

void funcb (B *b) {

b->print();
}

void funcc (C *c) {

c->print();
}

int main() {
B b;
C c;
funca(&c);
funcb(&c);
funcc(&c);
return 0;
}


Output:



    Class B print ()
Class B print ()









share|improve this question






















  • Kinda related, since a using declaration is not an overrider.
    – StoryTeller
    1 hour ago
















8














The Class B is overriding the pure Virtual Function "print()" of class A. Class C is inheriting Class B as well as having a "using A::print" statement.
Now why Class C is not an abstract class?



class A {
public :
virtual void print() =0;
};

class B:public A {
public:
void print();
};

void B :: print() {

cout << "nClass B print ()";
}

class C : public B {

public:
using A::print;
};

void funca (A *a) {

// a->print(1);
}

void funcb (B *b) {

b->print();
}

void funcc (C *c) {

c->print();
}

int main() {
B b;
C c;
funca(&c);
funcb(&c);
funcc(&c);
return 0;
}


Output:



    Class B print ()
Class B print ()









share|improve this question






















  • Kinda related, since a using declaration is not an overrider.
    – StoryTeller
    1 hour ago














8












8








8







The Class B is overriding the pure Virtual Function "print()" of class A. Class C is inheriting Class B as well as having a "using A::print" statement.
Now why Class C is not an abstract class?



class A {
public :
virtual void print() =0;
};

class B:public A {
public:
void print();
};

void B :: print() {

cout << "nClass B print ()";
}

class C : public B {

public:
using A::print;
};

void funca (A *a) {

// a->print(1);
}

void funcb (B *b) {

b->print();
}

void funcc (C *c) {

c->print();
}

int main() {
B b;
C c;
funca(&c);
funcb(&c);
funcc(&c);
return 0;
}


Output:



    Class B print ()
Class B print ()









share|improve this question













The Class B is overriding the pure Virtual Function "print()" of class A. Class C is inheriting Class B as well as having a "using A::print" statement.
Now why Class C is not an abstract class?



class A {
public :
virtual void print() =0;
};

class B:public A {
public:
void print();
};

void B :: print() {

cout << "nClass B print ()";
}

class C : public B {

public:
using A::print;
};

void funca (A *a) {

// a->print(1);
}

void funcb (B *b) {

b->print();
}

void funcc (C *c) {

c->print();
}

int main() {
B b;
C c;
funca(&c);
funcb(&c);
funcc(&c);
return 0;
}


Output:



    Class B print ()
Class B print ()






c++ using virtual-functions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Gtrex

411




411












  • Kinda related, since a using declaration is not an overrider.
    – StoryTeller
    1 hour ago


















  • Kinda related, since a using declaration is not an overrider.
    – StoryTeller
    1 hour ago
















Kinda related, since a using declaration is not an overrider.
– StoryTeller
1 hour ago




Kinda related, since a using declaration is not an overrider.
– StoryTeller
1 hour ago












1 Answer
1






active

oldest

votes


















6














From cppreference we read that




Using-declaration introduces a member of a base class into the derived class definition [...] If the derived class already has a member with the same name, parameter list, and qualifications, the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class.




As C inherits from B, there is already a virtual print member function, which is non-pure. This one hides/overrides the member function brought in by using A::print, and hence C is not an abstract class.






share|improve this answer





















  • That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
    – Oliv
    56 mins ago










  • @Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
    – lubgr
    31 mins ago










  • Your right this does not apply too to this case. Neither is the standard paragraph you site...
    – Oliv
    5 mins ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038898%2fapplying-using-keyword-on-c-pure-virtual-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














From cppreference we read that




Using-declaration introduces a member of a base class into the derived class definition [...] If the derived class already has a member with the same name, parameter list, and qualifications, the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class.




As C inherits from B, there is already a virtual print member function, which is non-pure. This one hides/overrides the member function brought in by using A::print, and hence C is not an abstract class.






share|improve this answer





















  • That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
    – Oliv
    56 mins ago










  • @Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
    – lubgr
    31 mins ago










  • Your right this does not apply too to this case. Neither is the standard paragraph you site...
    – Oliv
    5 mins ago
















6














From cppreference we read that




Using-declaration introduces a member of a base class into the derived class definition [...] If the derived class already has a member with the same name, parameter list, and qualifications, the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class.




As C inherits from B, there is already a virtual print member function, which is non-pure. This one hides/overrides the member function brought in by using A::print, and hence C is not an abstract class.






share|improve this answer





















  • That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
    – Oliv
    56 mins ago










  • @Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
    – lubgr
    31 mins ago










  • Your right this does not apply too to this case. Neither is the standard paragraph you site...
    – Oliv
    5 mins ago














6












6








6






From cppreference we read that




Using-declaration introduces a member of a base class into the derived class definition [...] If the derived class already has a member with the same name, parameter list, and qualifications, the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class.




As C inherits from B, there is already a virtual print member function, which is non-pure. This one hides/overrides the member function brought in by using A::print, and hence C is not an abstract class.






share|improve this answer












From cppreference we read that




Using-declaration introduces a member of a base class into the derived class definition [...] If the derived class already has a member with the same name, parameter list, and qualifications, the derived class member hides or overrides (doesn't conflict with) the member that is introduced from the base class.




As C inherits from B, there is already a virtual print member function, which is non-pure. This one hides/overrides the member function brought in by using A::print, and hence C is not an abstract class.







share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









lubgr

10.3k21745




10.3k21745












  • That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
    – Oliv
    56 mins ago










  • @Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
    – lubgr
    31 mins ago










  • Your right this does not apply too to this case. Neither is the standard paragraph you site...
    – Oliv
    5 mins ago


















  • That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
    – Oliv
    56 mins ago










  • @Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
    – lubgr
    31 mins ago










  • Your right this does not apply too to this case. Neither is the standard paragraph you site...
    – Oliv
    5 mins ago
















That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
– Oliv
56 mins ago




That is just wrong, derived class already has a member, means a member first declared in this class. See demo here: godbolt.org/z/ff5cEb
– Oliv
56 mins ago












@Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
– lubgr
31 mins ago




@Oliv Not sure if I get your point, why does it behave differently then based on the virtualness of the member function in question? If hiding or overriding both leads to an exclusion of the set of declarations introduced by the using declaration, shouldn't it exhibit identical behavior?
– lubgr
31 mins ago












Your right this does not apply too to this case. Neither is the standard paragraph you site...
– Oliv
5 mins ago




Your right this does not apply too to this case. Neither is the standard paragraph you site...
– Oliv
5 mins ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038898%2fapplying-using-keyword-on-c-pure-virtual-function%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Understanding the information contained in the Deep Space Network XML data?

Ross-on-Wye

Eastern Orthodox Church