does not name a type error

Hi, Code::Blocks keeps giving me this error message whenever I try to compile:
'LinkListIterator' does not name a type

I've checked for spelling errors in my preprocessor identifiers and header files, and made sure to include the appropriate header files in the implementation files. But Im stumped and have no idea how to fix this. Any assistance will be appreciated. Thanks.

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
// UnorderedLinkList.h

# ifndef H_UnorderedLinkList
# define H_UnorderedLinkList

# include "LinkListIterator.h"

struct NodeType
{
    int info;
    NodeType *link;
};

class UnorderedLinkList
{
    public:        
        LinkListIterator begin();
        LinkListIterator end();
        UnorderedLinkList();        

    protected:
        int count;
        NodeType *first;
        NodeType *last;
};

# endif 


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
// UnorderedLinkList.cpp

# include "UnorderedLinkList.h"
# include <iostream>
using namespace std;

LinkListIterator UnorderedLinkList::begin()
{
    LinkListIterator temp(first);

    return temp;
}


LinkListIterator UnorderedLinkList::end()
{
    LinkListIterator temp(NULL);

    return temp;
}

UnorderedLinkList::UnorderedLinkList()
{
    first = NULL;
    last = NULL;
    count = 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
// LinkListIterator.h

#ifndef H_LinkListIterator
#define H_LinkListIterator

# include "UnorderedLinkList.h"

# include <iostream>
using namespace std;

class LinkListIterator
{
    public:
        LinkListIterator();
        LinkListIterator(NodeType *ptr);
        int operator*(); // function to overload the dereferencing operator
        LinkListIterator operator++();// overloads the preincrement operator
        bool operator==(const LinkListIterator& right)const; // overloads the equal to operator
        bool operator!=(const LinkListIterator& right)const; // overloads the not equal to operator

    private:
        NodeType *current; // pointer to point to the current node in the ll

};
#endif 


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
// LinkListIterator.cpp

# include "LinkListIterator.h"

LinkListIterator::LinkListIterator()
{
    current = NULL;
}

LinkListIterator::LinkListIterator(NodeType *ptr)
{
    current = ptr;
}

int LinkListIterator::operator*()
{
    return current->info;
}

LinkListIterator LinkListIterator::operator++()
{
    current = current->link;
    return *this;
}

bool LinkListIterator::operator==(const LinkListIterator& right)const
{
    return(current == right.current);
}

bool LinkListIterator::operator!=(const LinkListIterator& right)const
{
    return (current != right.current);
}
Your headers are mutually inclusive. Only one of them can point to the other. To fix the inevitable compiler error: http://www.google.com/search?q=forward+declaration

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
//a.h
#include "b.h"

struct A{
    B *a;
};

//b.h
struct A;

struct B{
    A* a;
};
Last edited on
Thank you helios and Alvaro (cpp-home.com). Forward declaration solved the problem. I was trying to use NodeType and LinkListIterator before providing their definitions.
1
2
3
4
5
6
7
8
// LinkListIterator.h

class NodeType;

class LinkListIterator
{
    public:
...

1
2
3
4
5
6
7
8
// UnorderedLinkList.h

class LinkListIterator;

struct NodeType
{
    int info;
...

Last edited on
Topic archived. No new replies allowed.