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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:58:48+00:00 2026-06-02T15:58:48+00:00

When I try the two forms of constructor in classes of derivation hierarchy, the

  • 0

When I try the two forms of constructor in classes of derivation hierarchy, the result turns out to be different. Could anybody tell me why? Below are the test code.

//Person.h

#ifndef PERSON_H_
#define PERSON_H_
#include<string>

using std::string;

class Person{
    private:
        string firstname;
        string lastname;
    public:
        Person(const char *fn="NoName", const char *ln="NoName");   //A
        Person(const string &fn, const string &ln);
        virtual ~Person(){}

};

class Gunslinger:virtual public Person{
    private:
        int notchnum;       
    public:
        Gunslinger(const char*f="unknown",const char*n="unknown",int not=0);//B
        virtual ~Gunslinger(){}
};

class PokerPlayer:virtual public Person{

    public:
        PokerPlayer(const char*fn="unknown", const char*ln="unknown");//C;
        virtual ~PokerPlayer(){}
};    

class BadDude:public Gunslinger,public PokerPlayer{
    public:
        BadDude(const char*fn="unknown", const char*ln="unknown", int notc=0);//D

};

#endif

//PersonDefinition.cpp

#include"Person.h"
#include<iostream>
#include<cstdlib>

using std::cout;
using std::endl;
using std::cin;

Person::Person(const char*fn, const char*ln):firstname(fn),lastname(ln){
}

Person::Person(const string &fn,const string &ln):firstname(fn),lastname(ln){

}

Gunslinger::Gunslinger(const char*fn,const char*ln, int not):Person(fn,ln),notchnum(not){
}

PokerPlayer::PokerPlayer(const char*fn,const char*ln):Person(fn,ln){
}

BadDude::BadDude(const char*fn, const char*ln, int notc):Person(fn,ln),PokerPlayer(fn, ln),Gunslinger(fn,ln,notc){

}

//PersonTest.cpp

#include<iostream>
#include "Person.h"

int main(){
    Person a("Jack","Husain");
    PokerPlayer b("Johnson","William",8);
    Gunslinger c("Mensly","Sim");

}

So, here is the problem. The program above fails to compile with the default constructor with default value for all argument and throws an error message saying that “expected ‘,’ or ‘…’ before ‘!’ token”, but if I replace the default constructor in Line A,B,C,D with the form without argument, the program compiles and run successfully.Could anyone tell me why? Below is the error message.

error message

  • 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-02T15:58:52+00:00Added an answer on June 2, 2026 at 3:58 pm

    You did not implement all the constructors. For instance, you declared a constructor PokerPlayer::PokerPlayer(char*, char*) but you are trying to create a PokerPlayer with PokerPlayer b("Johnson","William",8); (i.e. you never declared a constructor which takes the third argument). The declaration you want for that previous line to work is PokerPlayer::PokerPlayer(char*, char*, int);

    Furthermore, you have the exact opposite problem when trying to declare a GunSlinger. Your GunSlinger class requires the third parameter and you are trying to declare it without that argument.

    Even though your base class supports several types of constructors, each derived class must also have every constructor you wish to use on it explicitly declared/implemented (with the exception of the default constructor).

    EDIT

    Here is some semi-functional code:

    class PokerPlayer : public Person
    {
      ...
      PokerPlayer(char* fname, char* lname, int val);
      ...
    };
    

    Implementation

    PokerPlayer::PokerPlayer(char* fname, char* lname, int val) : Person(fname, lname, val)
    {
      // Anything else we should do...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if you have 3 forms (shown below) and you set two of forms to
Below is example html, script and php to submit and reload two forms via
when i try to upload two files in the form, it doesn't happen!!! here
i try to compare two lists with each other: ListA (a1,a2,a3,...) ListB (b1,b2,b3,...) I
I try to create a two level mux which contains two wide muxes. Each
Two random question as I try to integerate Paypal IPN into my Codeigniter based
I have two models: The model NetworkObject try to describe hosts. I want to
I try to have some inheritance with attributeBindings between two View. (function(exports) { Ember.MobileBaseView
I am currently using two catch blocks after a try block. The first catches
hello guys i am try to print the output of two element data simultaneously

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.