tags:

views:

68

answers:

1

My error occurs on line 191 and 156. For some reason it is saying it cant find the default constructor when I have supplied the right amount of parameters.

The error it is giving me is "Cannot find default constructor to initialize base class"

code: http://pastebin.com/WLMvBMyy

If anyone could offer any input it would be greatly appreciated

+3  A: 
HField(int row, int column, int length, const char *s = NULL, void (*h)(void*) = NULL) {
        SField(row, column, length, s);
        ptrFunc = h;
}

This is not how you call base class constructors. The syntax you are looking for is:

HField(int row, int column, int length, const char *s = NULL, void (*h)(void*) = NULL) :
    SField(row, column, length, s) {
        ptrFunc = h;
}
Huw Giddens
Awesome! I just thought it might have been something to do with this too. Now my problem has been solved. Thank you!
John
@John: Since that solution works, you should click the "check" icon to accept the answer. And you might even up-vote it (click the little arrow icon above the vote count).
Mark Wilkins
Yeah, it says I need to wait 6 minutes before I can click the check mark. I'm waiting :)
John
To elaborate: What the original code was doing was constructing an anonymous SField object with function scope. C++ isn't Java and uses initialization lists instead. By omitting an initialization list that explicitly invokes the base class constructor, the compiler generates an invocation of the base class's default constructor for you, and that's why you get the error.
jamesdlin
Thanks for the explanation james, now I understand
John
You might aswell add `ptrFunc(h)` to the initialiser list instead of having it initialise empty and then be assigned in the body.
Greg Domjan
@John: Sorry about complaining. I was just jumping to conclusions since I saw that you had not accepted answers on any of the other questions you asked.
Mark Wilkins