SLNode Class operator<< help

I'm trying to do a cout operator on my code, but when I try to compile it's giving me an error. I know I'm overlooking something, but I can't pin point it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// file 
// name:
//test.cpp
#include <iostream>
#include "SLList.h"
#include "SLNode.h"

int main()
{
    SLNode node(5);

    std::cout << node << std::endl;

    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// file 
// name
//slnode.h
#ifndef SLNODE_H
#define SLNODE_H

class SLNode
{
public:
    SLNode(int data0=0, SLNode * next0=NULL)
        : data(data0), next(next0)
    {}
    int get_data()
    {
        return data;
    }
    
    SLNode get_next()
    {
        return next; //return *next?
    }
    
private:
    int data;
    SLNode * next;
};

std::ostream & operator<<(std::ostream & cout, SLNode & n)
{
    cout << "<SLNode "
         << &n
         << ", data: "
         << n.get_data()
         << ", next: "
         << n.get_next() //problem is in this
         << '>';
    return cout;
}

#endif


Here's the last error the compiler is giving me:
In file included from SLList.h:6:0,
from test.cpp:5:
SLNode.h:35:24: note: ‘SLNode’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’

It's saying something about a string, which has got me confused.

Thanks in advance for the help
You're returning a pointer with get_next() so shouldn't the signature be: SLNode * get_next()
Wow, I knew it was something small that I was over looking. Thanks Norm.
Topic archived. No new replies allowed.