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

  • Home
  • SEARCH
  • 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 1110785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:26:48+00:00 2026-05-17T02:26:48+00:00

Consider: struct device{ virtual void switchon() = 0 {} }; int main() { }

  • 0

Consider:

struct device{
    virtual void switchon() = 0 {}
};

int main()
{

}

I wrote code similar to following and it gave an error:

pure-specifier on function-definition
compilation terminated due to
-Wfatal-errors.

When I asked him, he showed me the following quote from the standard:

A virtual function declared in a class
shall be defined, or declared pure
(10.4) in that class, or both; but no
diagnostic is required (3.2).

I can’t seem to understand what it means and I think this somehow is not relevant.

PS: If this is not the relevant quote, please guide me to the proper one so that I can have a better counterargument.

  • 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-05-17T02:26:48+00:00Added an answer on May 17, 2026 at 2:26 am

    A pure virtual function may have a definition (out of class definition). That is completely optional. But what you are trying to do is plain wrong because

    C++03 [Section 10.4/2] says:

    [Note: a function declaration cannot provide both a pure-specifier and a definition —end note] [Example:

    struct C {
        virtual void f() = 0 { }; // Ill-formed
    }
    

    However you are free to write

    struct device{
        virtual void switchon() = 0;
    };
    
    void device::switchon() { } // Definition {optional}
    
    int main()
    {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: struct Foo { mutable int m; template<int Foo::* member> void
consider the following code:- struct mystruct { int data; struct mystruct *next; }; void
Java noob question: Consider the following C array and initializer code: struct { int
Consider the following code: #include <iostream> struct foo { // (a): void bar() {
Consider the following C++ code: struct X { int a; int b; }; X
Consider the following code struct foo { const int txt_len; const int num_len; char
Consider the following code: #include <iostream> struct X{ X(){ throw 0; } }; void
Consider the following snippet: struct ObjectInterface { virtual ~ObjectInterface() {} virtual void Print(std::ostream& target)
Consider the following: struct Foo { char c; int i; }; void Bar(void) {
Consider the following code: struct s { const int id; s(int _id): id(_id) {}

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.