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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:24:56+00:00 2026-05-27T17:24:56+00:00

I am trying to call a constructor of a Base Class in a function

  • 0

I am trying to call a constructor of a Base Class in a function of Derived Class. Here is the code:

Classes:

#pragma once

#include "CAR_TYRE_DOOR.h"
#include <string>
using namespace std;
//#ifndef 1_A_H_B
//#define 1_A_H_B

class Honda_Civic: public Car
{
private:
    string CNG_y_n;
public:
    Honda_Civic();
    Honda_Civic(string CNG);
    Honda_Civic(Honda_Civic& H1);

    void set_CNG_y_n(string S);
    string get_CNG_y_n();
    void print();
};
class BMW: public Car
{
private:
    string conv_y_n;
public:
    BMW();
    BMW(string S);
    BMW(BMW& BMW1);
    void set_conv_y_n(string S);
    string get_conv_y_n();
    void print();
};
class Mercedes: public Car
{
private:
    int no_WS;
    string SGR_y_n;
public:
    Mercedes();
    Mercedes(int no_WS, string SGR_y_n);
    Mercedes(Mercedes& Merc);

    //::Car( Merc1);

    void set_no_WS(int n);
    void set_SGR(string SGR);
    int get_no_WS();
    string get_SGR();
    void print();
};

//#endif

The BaseClass functions:
//#include "BMW+MERC.h"
#include "CAR_TYRE_DOOR.h"
#include "Honda.h"
#include "S_R.h"
#include <iostream>
#include <string>

using namespace std;

void Car::set_color(string S)
{
    S = this->color;
}

void Car::set_model(string S)
{
    S = this->model;
}

void Car::set_cost(float x)
{
    x = this->cost;
}

string Car::get_color()
{
    return this->color;
}

string Car::get_model()
{
    return this->model;
}

float Car::get_cost()
{
    return this->cost;
}
Car::Car()
{
}
Car::Car(string color, string model, float cost)
{
    this->color = "white";
    this->model = "2011";
    this->cost = 1000000;
}
Car::Car(Car& C1)
{
    this->color = C1.color;
    this->model = C1.model;
    this->cost = C1.cost;

    for(int i=0; i<4; i++)
    {
        DX[i] = C1.DX[i];
    }

    for(int i=0; i<4; i++)
    {
        TX[i] = C1.TX[i];
    }
}
void Car::print_car()
{
    cout <<"Car color: "<<get_color()<<endl;
    cout <<"Car model: "<<get_model()<<endl;
    cout <<"Car door color: "<<DX[0].get_color()<<endl;
    cout <<"Car door vendor: "<<DX[0].get_vendor()<<endl;

    cout <<"Tyre vendor: "<<TX[0].get_vendor()<<endl;
    for(int i=0; i<4; i++)
    {
        cout <<"Tyre"<< i+1 <<"type: "<<TX[i].get_rubber_type()<<endl;
    }


}
The Derived Class:
#include "Honda.h"
#include <iostream>
#include <string>
using namespace std;

Mercedes::Mercedes()
{
}
Mercedes::Mercedes(int no_WS, string SGR_y_n)
{
    this->no_WS = 4;
    this->SGR_y_n = "Yes";
}
Mercedes::Mercedes(Mercedes& Merc)
{
    Mercedes::Car( Merc);

    this->no_WS = Merc.no_WS;
    this->SGR_y_n = Merc.SGR_y_n;
}
void Mercedes::set_no_WS(int n)
{
    this->no_WS = n;
}
void Mercedes::set_SGR(string SGR)
{
    this->SGR_y_n = SGR;
}
int Mercedes::get_no_WS()
{
    return this->no_WS;
}
string Mercedes::get_SGR()
{
    return this->SGR_y_n;
}
void Mercedes::print()
{
    Mercedes.print_car();

    cout <<"Number of Woofer Speakers: "<<get_no_WS()<<endl;
    cout <<"Sunglass Roof: "<<get_SGR()<<endl;
}

Now in the copy constructor of the derivedclass, i am trying to call the copy constructor of the base class using:

Mercedes::Mercedes(Mercedes& Merc)
{
    Mercedes::Car( Merc);

    this->no_WS = Merc.no_WS;
    this->SGR_y_n = Merc.SGR_y_n;
}
See this: Mercedes::Car( Merc);

to implement this, please tell me the syntax.

  • 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-27T17:24:57+00:00Added an answer on May 27, 2026 at 5:24 pm

    The proper way to call constructor hierarchies is like this:

    class Car
    {
        public:
            Car () { }
            Car (cosnt Car &) {}
    };
    
    class Mercedes : public Car
    {
        public:
            Mercedes () { }
            Mercedes (const Mercedes &) {}
    };
    
    Mercedes :: Mercedes () : Car() { }
    Mercedes :: Mercedes (const Mercedes &car) : Car(car) { }
    

    A copy constructor looks like this (notice the const):

    Class :: Class (const Class &)

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

Sidebar

Related Questions

I'm trying to call an accessor function in a copy constructor but it's not
I'm trying to call a function after I load some XML into Actionscript, and
I'm trying to derive a new class from an old one. The base class
While refactoring some code, I came across this strange compile error: The constructor call
I was trying to make a constructor function and within it, i had/wanted to
Am trying to move an antique C++ code base from gcc 3.2 to gcc
I'm trying to call my good old 'RegisterClientScriptBlock' on the friendly 'ScriptManager' class. It
I am trying to call to make a 2-arg constructor the default constructor. By
I am trying to call a method from the constructor of my javascript constructor,
I am trying to learn how to work with 'classes' in javascript. Here is

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.