i Have a pure virtual function called print(). In each of my derived classed i have the function with it giving the commands
cout<<information<<number<<endl;
This works fine, but i want to print out the data to an outputfile which i have created in my main code. When i add the following to the print function to make it
i was able to get this into my classes without any errors but unfortunately when i call it in my main adn go to the output file nothing is printed.
THIS IS MY PURE VIRTUAL FUNCTION IN MY ABSTRACT BASE CLASS:
virtual void printf(std::ostream &out)=0;
THIS IS THE FUNCTION WRITTEN IN EACH OF THE DERIVED CLASSES.
void printf(std::ostream &out)
{
out<<"Student name: "<<sname<<" Student ID:"<<stdid<<endl<<endl<<lecture<<endl;
}
1) Please use legitimate English and correct your typos. I don't want to solve your words, I want to solve your problem.
2) The topic title is very vague. I see so many topics like this. Gee, why don't I pull out a gun and shoot everyone who makes these topics? According to Hitler, that works great for making the world a better place. But sorry mbcx7mm3 (your name? what the hell??), I'm not radical.
I get the error ' out was not declared in this scope '. Anybody know why this is and how i can correct it?
Apologies if i have annoyed you, mbcx7mm3 is just my username from work. And the typos, are because i am slightly dyslexic. I am relatively new to C++ and i am trying my best to learn.
Basically this is my issue,
I have a pure virtual function defined within my abstract base class 'virtual void print()=0;' . Within my derived class which is called 'physics' the function is coded as:
This works fine, and prints out to the command window. However, i wish to also print out to a file and currently i can only do this by using the command within my main:
out<<physics;
i wish to however have a similar function as print() contained within my derived class which will print out to a file, calling the function printf(). Why is it not possible to write:
This means your student::printf function was never defined. This is usually because the coder forgot to declare it as a pure virtual function with "=0"
1 2 3 4
class student {
public:
virtualvoid printf(std::ostream &) = 0;
}
"vtable for student", referenced from:
Given the above error, I'd guess you also forgot to add the virtual keyword, resulting in a student class with no vtable.
"typeinfo for student", referenced from:
I'm not sure what would cause this. Correct the other errors, and then show us the entire student class if the problem is still there.