When trying to compile my code i get the following errors every time.
These are the errors:
C:\...\main.cpp In file included from main.cpp
C:\...\triangle.h In constructor `trianglePlus::trianglePlus(double, double, double, char*)':
C:\...\triangle.h expected `{' at end of input
C:\...\Makefile.win [Build Error] [main.o] Error 1
And here’s a stripped down version of my program.
triangle.h :
class triangle {
double x;
double y;
double z;
public:
triangle(double a,double b,double c);
};
class trianglePlus: public triangle {
char * name;
public:
trianglePlus(double a,double b,double c,char * v):triangle(a,b,c);
};
When removing the commented section it gives me even more errors.
main.cpp
#include <cstdlib>
#include <iostream>
#include <math.h>
#include "triangle.h"
using namespace std;
triangle::triangle(double a, double b, double c) {
x = a;
y = b;
z = c;
}
/*
trianglePlus::trianglePlus(double a,double b,double c,char * v):trijsturis(a,b,c) {
x = a;
y = b;
z = c;
name = new char[20];
strcpy(name,v);
}
*/
int main()
{
system("PAUSE");
return 0;
}
Any ideas what could be wrong?
Your constructor needs to be either fully defined or only declared. Since you want to specify the initializer list, you need to define the full constructor. Best like this, inline in the class definition:
Alternatively, just put the declaration in the header, and the definition in the source file: