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 6587087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:52:24+00:00 2026-05-25T16:52:24+00:00

Sorry for the Noob question .I have been learning C++ for a while and

  • 0

Sorry for the Noob question .I have been learning C++ for a while and from the book “Visual C++” by Ivor Horton I see that when extending some class the methods overriding is done in the header of the derived class.I haven’t found any example where it can be done in .cpp files.So my question is if the .cpp files can only contains the “native” methods of the current class?Or there is a way also to override parent methods there.

  • 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-25T16:52:25+00:00Added an answer on May 25, 2026 at 4:52 pm

    You can use .h and .cpp as you wish. You can have both declaration and definition in both .h and .cpp’s. Not that you should, but you can. cpp’s are compiled by the compiler, if you include your .h in a cpp, it will also be compiled. So to answer your question, yes, you can override in the cpp.

    Example:

    A.h

    class A{
    public:
       A() {};//definition and declaration in header
       virtual void foo() {};
    };
    

    B.cpp

    #include "A.h"
    
    class B : public A{
    public:
        B() {};//definition and declaration in source file
        virtual void foo() {};
    };
    
    int main()
    {
        A* pA = new B;
        pA->foo(); //will call foo from B
        return 0;
    }
    

    B will however only be visible in B.cpp.
    Don’t do it thoguht!

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

Sidebar

Related Questions

Sorry if this is a noob question, but I have been given the dubious
In advance: sorry for the noob question but I'm learning Cocoa & Objective-C and
Hi Sorry for this noob question but here goes...i have a working slidetoggle on
sorry for the (probably) noob question, but I', new at this stuff. i have
Question: Hello All, Sorry that this is kind of a noob question. I just
Sorry, hope no one marks me down for a noob question, I don't have
I am sorry, that sounds like a noob question. I am trying to do
Sorry if this sounds like a noob question. I downloaded this asp.net project from
Yes, it's a noob question... I have been using Dev-C++ for all my projects
Sorry for the noob question I'm just a little confused. If I have an

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.