M
Mark
I can't seem to get this subclass to upcast to a baseclass... see
comments below
#include <cstdlib>
#include <iostream>
#include "Base.h"
#include "Sub1.h"
using namespace std;
void f(Base* b)
{
cout << "ok";
}
int main(int argc, char *argv[])
{
Sub1* s1;
Base* b;
f(s1); // how come I can do this
s1 = b; // but not this??
system("PAUSE");
return EXIT_SUCCESS;
}
the compiler complains..
19 invalid conversion from `Base*' to `Sub1*'
and if you need the header files..
#ifndef SUB1_H
#define SUB1_H
#include "Base.h"
class Sub1 : public Base
{
public:
Sub1* clone();
};
#endif
#ifndef BASE_H
#define BASE_H
class Base
{
public:
Base* clone();
};
#endif
help appreciated.
comments below
#include <cstdlib>
#include <iostream>
#include "Base.h"
#include "Sub1.h"
using namespace std;
void f(Base* b)
{
cout << "ok";
}
int main(int argc, char *argv[])
{
Sub1* s1;
Base* b;
f(s1); // how come I can do this
s1 = b; // but not this??
system("PAUSE");
return EXIT_SUCCESS;
}
the compiler complains..
19 invalid conversion from `Base*' to `Sub1*'
and if you need the header files..
#ifndef SUB1_H
#define SUB1_H
#include "Base.h"
class Sub1 : public Base
{
public:
Sub1* clone();
};
#endif
#ifndef BASE_H
#define BASE_H
class Base
{
public:
Base* clone();
};
#endif
help appreciated.