Lets say I have 2 classes: foo and foo2 who are written as such:
foo.h:
#ifndef __InheritanceTest__foo__
#define __InheritanceTest__foo__
#include <stdio.h>
class foo
{
public:
foo();
int getSize();
protected:
int size;
};
#endif
foo.cpp:
#include "foo.h"
foo::foo()
{
size = 23;
}
int foo::getSize()
{
return size;
}
foo2.h:
#ifndef __InheritanceTest__foo2__
#define __InheritanceTest__foo2__
#include <stdio.h>
#include "foo.h"
class foo2: foo
{
public:
foo2();
};
#endif
foo2.cpp:
#include "foo2.h"
foo2::foo2()
{
size = size *2;
}
this is my main:
#include <iostream>
#include "foo.h"
#include "foo2.h"
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
foo2 f2;
int i = f2.getSize();
std::cout << i << "\n";
return 0;
}
I'm getting two errors:
'getSize' is a private member of foo
and
cannot cast foo2 to its private base class foo.