J
jjsavage
Hi everyone,
Ok, I've got a base class called attribute, with a virtual print()
function. Attributes are never really instantiated, because it has to
be a continuous_attribute or a nominal_attribute (the derived classes).
But I need a list of attributes, and list<attribute> crashes if the
print() function (or any function) is pure virtual. Continuous and
nominal both have their own print() function, overriding the base
print(). So I fill my list<attribute> with continuous or nominal
attributes, but when I iterate through the list and print() each
element, all I ever get is the base attribute's print()! Here's the
snippets:
class attribute
{
public:
virtual void Print(void) { cout << "should never see this\n";}
};
class continuous_attribute: public attribute
{
public:
void Print(void) { cout << "continuous\n"; }
};
class nominal_attribute: public attribute
{
public:
void Print(void) { cout << "nominal\n"; }
};
list<attribute> schema;
for (list<attribute>::iterator iter = schema.begin(); iter !=
schema.end(); iter++)
{
iter->Print();
}
And all I see are "should never see this". What am I doing wrong?
Thanks,
John Savage
Ok, I've got a base class called attribute, with a virtual print()
function. Attributes are never really instantiated, because it has to
be a continuous_attribute or a nominal_attribute (the derived classes).
But I need a list of attributes, and list<attribute> crashes if the
print() function (or any function) is pure virtual. Continuous and
nominal both have their own print() function, overriding the base
print(). So I fill my list<attribute> with continuous or nominal
attributes, but when I iterate through the list and print() each
element, all I ever get is the base attribute's print()! Here's the
snippets:
class attribute
{
public:
virtual void Print(void) { cout << "should never see this\n";}
};
class continuous_attribute: public attribute
{
public:
void Print(void) { cout << "continuous\n"; }
};
class nominal_attribute: public attribute
{
public:
void Print(void) { cout << "nominal\n"; }
};
list<attribute> schema;
for (list<attribute>::iterator iter = schema.begin(); iter !=
schema.end(); iter++)
{
iter->Print();
}
And all I see are "should never see this". What am I doing wrong?
Thanks,
John Savage