What Dumb Little Detail Am I Missing?

Hi Guys,

I have this class CTrainLine with a struct called ListNode and a ListNode pointer called head. On the contructor, I'm trying to use the new function with head to create a new ListNode, and I'm getting this error:


line 22: no matching function for call to `CTrainLine::ListNode::ListNode()'


I just did something exactly like this in another program and it works fine, and I can't see why it isn't now. Any insight would be greatly appreciated.

All the best, thank you very much!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

#include "Platform.hpp"
#include <iostream>

using namespace std;

class CTrainLine{
    public:
        struct ListNode{
            Platform data;
            ListNode * next;
        };
        CTrainLine();

    private:
        ListNode * head;
        int size;  
};

CTrainLine::CTrainLine() {
	size = 0;
	head = new ListNode;
}
Does Platform have a default constructor?
No it does not! I suppose that must be the problem. I could always add one, I suppose, but If possible I'd rather not do it JUST for this. Out of curiosity, is there any other way to get past this? Or do I just need to suck it up and add a default constructor?

Much thanks,
You could get around it by supplying an argument to the Platform constructor from a List Node constructor:

1
2
3
4
5
       struct ListNode{
            Platform data;
            ListNode * next;
            ListNode() : data( /* argument here */ ), next(nullptr) {}  
        };
Brilliant! Thanks guys! =]
Topic archived. No new replies allowed.