Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:07:50+00:00 2026-06-12T00:07:50+00:00

I have a class Base with a pure virtual function f() . Another class

  • 0

I have a class Base with a pure virtual function f(). Another class Derived derives from Base. I call f() from within Derived. And using g++, I get an error from the linker.

[agnel@dooku tmp]$ g++ pure_virtual_function_call.cpp 
/tmp/ccGQLHi4.o: In function `Derived::f()':
pure_virtual_function_call.cpp:(.text._ZN7Derived1fEv[_ZN7Derived1fEv]+0x14): undefined reference to `VirtualBase::f()'
collect2: error: ld returned 1 exit status

It seems to me that the error was caught by the linker. Why didn’t the compiler report this error? Why leave it to the linker?

Here is the code:

#include <iostream>

using namespace std;

class VirtualBase {
public:
    virtual void f() = 0;
};

class Derived : public VirtualBase {
public:
    void f(){
        VirtualBase::f();
        cout << "Derived\n" ;
    }
};


int main(){
    Derived d;
    d.f();
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:07:51+00:00Added an answer on June 12, 2026 at 12:07 am

    Because pure virtual functions can have definitions and, if they do, you are allowed to call them non-virtually using the syntax VirtualBase::f().

    The compiler has no way to tell whether you intend the function to be defined or not, and so the error can only be detected by the linker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a base class with a pure-virtual function, and a derived class
I have a function X() declared as PURE VIRTUAL in base class: class Base
I have a base class MyBase that contains a pure virtual function: void PrintStartMessage()
C++: I have a base class A with a pure virtual function f() and
The pure virtual destructor in base class should have a definition. Otherwise compiler will
Say we have an abstract base class IBase with pure virtual methods (an interface).
I have a base class class Animal with pure virtual functions, and a set
I have an abstract class defining a pure virtual method in c++: class Base
I have created an abstract base class, which has a pure virtual method with
For example, I have the base class with pure virtual functions: class IBase {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.