CJCoding With Joseph
15per day
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #24

Private Member in Base Class

easyInheritance

This code fails to compile. What is the issue?

📄 Code

1#include <iostream>
2using namespace std;
3 
4class Animal {
5private:
6 string name;
7public:
8 Animal(string n) : name(n) {}
9};
10 
11class Dog : public Animal {
12public:
13 Dog(string n) : Animal(n) {}
14 void print() {
15 cout << name << endl;
16 }
17};