Strange error on one code, but not another?

I have a function, defined like this:
1
2
3
4
void AddFormatElement(const string& Name, const FormatElement& New)
{
  //code
}


FormatElement is the base class for two other classes, GenericElement and Format, which publicly inherit from FormatElement. I have two pieces of code here:
1
2
3
GenericElement ge;
ge.DoStuff();
AddFormatElement(name, ge);
1
2
3
Format fmt;
fmt.DoStuff();
AddFormatElement(name, fmt);


The second piece of code compiles without a hitch, but the first gives me this error:
error C2243: 'type cast' : conversion from 'GenericElement *' to 'const FormatElement &' exists, but is inaccessible

The error is on the line AddFormatElement(name, ge);

The full code can be seen here: http://paste.pocoo.org/show/405290/

I am struggling to understand this error, and why it happens for the first piece of code and not the second. Any help is appreciated.
Last edited on
You're using private inheritance for both derived classes. The compiler doesn't complain about Format because you're inside one of its member functions.

The MSDN has pretty good explanations about compiler errors, by the way.
Oops! I was using public inheritance originally, but I had to rewrite my code at one point to simplify it, and I forgot the public specifiers. Thanks!
Topic archived. No new replies allowed.