function in classes

Apr 13, 2011 at 2:48pm
Hi,

Basically i have 3 classes derived from and abstract base class. In my main i have a switch case statement with three case's one for an object created of each class type. I have a function which is pretty much identical for in each of the cases in my main and i would like to instead declare it within the classes using a pure virtual function in my abstract base class.

ostringstream ofss;

ofss <<" "<<clec<<" "<<cgrade<<" %"<<endl;

string outputFilename(ofss.str());

(clec and cgrade are previously declared)

This is few lines of code i have in my main of which i wish to write as a function inside my classes, and the pure virtual function of it declared in abstract base class, which will simply when called return a string.

Would really appreciate anyhelp as i have tried so many different ways of writing the function and i can't seem to get it to work.
Apr 13, 2011 at 3:35pm
Try

virtual string void()=0;

and

string newcourse(string course, double grade)
{
ostringstream ofss;

ofss<<course<" "<<grade<<"%"<<endl;

string temp(ofss.str());
return temp;
}
in each of the 3 derived classes.
Topic archived. No new replies allowed.