Hello
For someone new to not only C++ but also C, it would be best to start with one or more tutorials. That would help you understand the most important basics and some basic program that you can then extend to try out more advanced stuff by yourself.
Here's a decent tutorial on Cplusplus.com, which is also a good reference site for advanced language features:
C++ language tutorial
As to your questions:
1. a class that has one or more
pure virtual functions cannot be instantiated. This is what is called a (pure) virtual, or 'abstract' class. Typically you use such classes if all you want to do is describing a specific behaviour, rather than the entire definition of the real class, or if you want to describe behaviour that is shared by several related classes.
Example:
class Shape {
public:
virtual void draw() = 0; };
#include "Shape.h" // read declaration of the base class Shape
class Triangle : public Shape {
public:
virtual void draw(); };
#include "Triangle.h"
void Triangle::draw() {
}
(and now do the same for other types of shapes, e. g. Circle, Square)
#include "Shape.h"
#include "Triangle.h"
#include "Circle.h"
#include "Square.h"
int main() {
Shape* shapes[3];
shapes[0] = new Triangle();
shapes[1] = new Square();
shapes[2] = new Circle();
for (int i = 0; i < 3; ++i) {
shapes[i].draw();
}
for (int i = 0; i < 3; ++i) {
delete shapes[i];
}
return 0;
}
Now, if you could instantiate an object of class
Shape
and assign it to your
shapes
array, what do you think the call to
draw()
would do? You don't know? Well, the compiler doesn't either. That's why it is forbidden.
(rest of the questions in separate solution(s))