Question
The following C++ code has a common inheritance-related issue. How can it be debugged to ensure the derived class constructor properly initializes the base class? #include #include class Person { public: std::string name; Person(std::string
The following C++ code has a common inheritance-related issue. How can it be debugged to ensure the derived class constructor properly initializes the base class? #include #include class Person { public: std::string name; Person(std::string
n) : name(n) {} }; class Student : public Person { public: int studentId; Student(std::string n, int id) { // Problematic: Base class not initialized studentId = id; } void display() { std::cout << "Name: " << name << ", ID: " << studentId << std::endl; } }; int main() { Student s("Alice", 101); s.display(); return 0; }
More IT Operating System Questions
- What is the time complexity of the Floyd-Warshall algorithm for a graph with V vertices?
- In a Resource Allocation Graph with single-instance resources, a cycle P1→R1→P2→R2→P1 exists. What does this indicate?
- Consider the following statement regarding DIAC. Statement (1): DIAC is unidirectional device. Statement (2): DIAC can be used for triggering TRIAC. Sta...
- A greedy algorithm is used to make change for a given amount using a set of coin denominations. For denominations {1, 5, 10, 25} and an amount of 30, it wo...
- Which algorithm is used in game playing for decision making?
- Which service model offers virtual machines and storage resources?
- A system uses 32-bit virtual addresses, a page size of 4 KB, and a single-level page table where each page table entry (PTE) occupies 4 bytes. What is the ...
- Which type of cable is referred to as K-type or Category 5e/6 in network infrastructure, and what is its maximum standard data transfer rate for Category ...
- Which of the following is a blueprint for creating objects?
- A kernel-level thread performs a blocking system call while other threads of the same process are runnable. What is the usual result?
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)