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

The Archive Base Latest Questions

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

Could you please check out this piece of code: #include <vector> class A {

  • 0

Could you please check out this piece of code:

#include <vector>
class A
{
public:
    A(int a, int b);
};

class C :public A
{
public:
    C(int a, int b):A(a,b){}
    static C instances;
};

C C::instances;

int main()
{
    return 1;
}

The compilation gives me error as:

$ c++ inheritance.cpp 
inheritance.cpp:16:6: error: no matching function for call to ‘C::C()’
inheritance.cpp:16:6: note: candidates are:
inheritance.cpp:12:2: note: C::C(int, int)
inheritance.cpp:12:2: note:   candidate expects 2 arguments, 0 provided
inheritance.cpp:8:7: note: C::C(const C&)
inheritance.cpp:8:7: note:   candidate expects 1 argument, 0 provided

I need C to inherit from A and I need A to have arguments in its constructor.
Finally, I need the instance’s static variable to be declared and defined with no arguments.
So is there a solution to that? I value your kind comments.

Another point to note:
if the static variable was a container, like:

static std::vector instances;

the code would compile just fine. Why?

EDIT:

Thanks for all the answers,
but, if I modify C C::instances; to C C::instances(0,0); i will get another error:
$ c++ inheritance.cpp
/tmp/cctw6l67.o: In function C::C(int, int)':
inheritance.cpp:(.text._ZN1CC2Eii[_ZN1CC5Eii]+0x1b): undefined reference to
A::A(int, int)’
collect2: ld returned 1 exit status

any idea why? and how to fix it?

thanks

  • 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-06T00:07:28+00:00Added an answer on June 6, 2026 at 12:07 am

    If you define a constructor, the compiler no longer generates a default one for you, which you attempt to call with C C::instances;. You can bypass this by calling the available constructor:

    C C::instances(0,0);
    

    or provide a default constructor for C.

    With

    static std::vector<C> instances;
    

    it compiles because no elements are created, and std::vector has a default constructor which initializes an empty vector. But

    C::instances.push_back(C());
    

    wouldn’t compile.

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

Sidebar

Related Questions

Could some on please check out this URL with Mozilla - http://smartplast.com/soon/ . As
Could someone please suggest why this is happening... I’ve got some code to pretty
Could someone please explain why this is happening? var y = new int[]{1,2}; Console.WriteLine(y
yes, this is a homework-type question but could you please help me out? In
Could all those CORBA experts out there please help me with this one. I
Could someone please advice why i have a memory leak in this code? I
Could some on with Firebug or other tool check out this page. Take a
This simple code: [HttpPost] public ActionResult Check(string chosen_username, string email) { var lang =
I got this piece of code: public void cap_search(){ EditText search = (EditText) findViewById(R.id.search);
Please could someone post an example of how to check if an element exists

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.