In your
line
interface, you declared the members
first
and
last
of type
point
(side-tip: adopt some naming convention which let's you distinguish more easily between types and variables, e.g. let all user defined types start with a capital). Normally, the compiler will define a default-constructor for your class. However, when you provide a non-default one yourself (like you did in the
point
class), the compiler will omit its default implementation from the interface! This is why you don't have a default constructor, but why does the compiler require you to define one?
Let's take a look at what your
line
constructor looks like:
line(point &f,point &l)
{
first=f;
last=l;
}
You should know that
before the body of the constructor runs, the class-members have
already been initialized. This means that the compiler will look for the default constructor of the
line
members. C++ offers a facility called
member initializers, which are handled before the body of your constructor. All members that are not explicitly initialized by the programmer using member initializers (or similar C++11 features) will be default-initialized by the compiler. The syntax for member initializers is like so:
line(point &f,point &l)
: first(f),
last(l)
{}
It might even be faster, as they will only be initialized once instead of twice in your code.
Conclusion: if your members don't offer default constructors, you have to provide member initializers with the appropriate arguments.
EDIT: Forgot to include a very useful, still maintained, online resource (by my former C++ teacher):
http://www.icce.rug.nl/documents/cplusplus/[
^]. Paragraph 7.3 handles this issue :-)