[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Inaccessible base??

Posted on 2006-05-20
3
Medium Priority
?
1,291 Views
Last Modified: 2012-06-21
I have 4 files named "Animal.h", "Bird.h", "Canary.h" and "main.cpp" as shown below. When I compile, it tells me that "Animal is an inaccessible base of "Canary"... what does the problem come from?

#ifndef ANIMAL_H
#define ANIMAL_H
#include <iostream>
using namespace std;

class ANIMAL{      
     public:
             inline ANIMAL();
             virtual void talk(void) const = 0;
};

inline ANIMAL::ANIMAL()
{
}
#endif

#ifndef BIRD_H
#define BIRD_H
#include "Animal.h"

class BIRD : ANIMAL{
      public:
             inline BIRD();
             virtual void talk(void) const = 0;
};

inline BIRD::BIRD()
{
}
#endif

#ifndef CANARY_H
#define CANARY_H
#include "Bird.h"

class CANARY : public BIRD{
      public:
             inline CANARY();
             inline virtual void talk(void) const;
};

inline CANARY::CANARY()
{
}

inline void CANARY::talk(void) const{
       cout << "I am Canary" << endl;
}
#endif

#include <iostream>
#include "Animal.h"
#include "Canary.h"
using namespace std;

int main(void)
{
    ANIMAL *pets[1];
    pets[0] = new CANARY;
    pets[0]->talk();
    return 0;
}
0
Comment
Question by:kennysflau
  • 2
3 Comments
 
LVL 30

Assisted Solution

by:Axter
Axter earned 180 total points
ID: 16725295
Hi kennysflau,
> class BIRD : ANIMAL{

The above line needs pulic declaration for derived ANIMAL
Exampl:
class BIRD : public ANIMAL{


Cheers!
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 16725299
Hi, change

class BIRD : ANIMAL{

to


class BIRD :public ANIMAL{


---
Harish
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 320 total points
ID: 16725304
kennysflau, eventhough you are deriving CANARY from BIRD as public, the class BIRD is derived from ANIMAL as private (default). So, ANIMAL is inaccessible to CANARY class
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question