0

I get the error 'MyIsland does not name a type', but do not get the error 'MyList does not name a type'. Why and how can I fix this?

Edit: I think it is due to having the list class in the header file but the MyIsland class in a separate file, but is there a way to fix this without moving the MyIsland class?

Here are a part of my files:

main.cpp

#include "header.h"

class ArchipelagoExpedition
{
 private:
  MyIsland* darr;
  int islands;

 public:
  ArchipelagoExpedition();
  ArchipelagoExpedition(int is);
...

Island.cpp

#include "header.h"

class MyIsland
{
private:
    MyList adjList;
    MyList visList;
public:
...

MyListAndNode.cpp

//list methods
...
}

header.h

//list and node class
...
thegoodhunter-9115
  • 317
  • 1
  • 3
  • 15

2 Answers2

1

Your program cannot find MyIsland. Read this to find out why.

The declarations of your classes should be in header files (.h, .hpp...), and the implementations in source files (.cc, .cpp...). In your case, I would do something like this:

  • class List
    • list.hpp (declaration)
    • list.cpp (implementation)
  • class Island
    • island.hpp (declaration)
    • island.cpp (implementation)

In the above case, you should include list.hpp in island.hpp, island.hpp in main.cpp and it will work.


Doeus
  • 430
  • 1
  • 3
  • 7
0

Oh... I had the same problem now. It was caused by the declaration of an enum with the same element as the name of the class, like:

enum Templates
{
    Temp1,
    Temp2
};
class Temp1
{
};
class Temp
{
    Temp1 m_temp1; // error here
};

That's why enums should be written by capital letters. Check if you do not have something similar.

Norbert
  • 11
  • 3