Perhaps it is a header problem of sorts... But this is what's happening:
The compiler is giving me an error on the line:
Queue<Email> mailbox;
This is the error:
..\EmailSystem.h:25: error: ISO C++ forbids declaration of `Queue' with no type
..\EmailSystem.h:25: error: expected `;' before '<' token
Queue.h:
#ifndef QUEUE_H_
#define QUEUE_H_
#include <string>
#include "EmailSystem.h"
...
template <class B>
class Queue {
...
};
#endif /* QUEUE_H_ */
Queue.cpp:
#include "Queue.h"
...
template class Queue<Email>;
EmailSystem.h:
#ifndef EMAILSYSTEM_H_
#define EMAILSYSTEM_H_
#include <iostream>
#include <string>
#include <vector>
#include "Queue.h"
struct Email {
...
};
struct User {
std::string name;
Queue<Email> mailbox;
};
...
#endif /* EMAILSYSTEM_H_ */
You have a circular include. Queue.h
includes EmailSystem.h
and EmailSystem.h
includes Queue.h
so the include guards make sure that the header has no effect the second time it is being included. This means if Queue.h
is the first to be included then Queue
will not yet be declared before it is first used in EmailSystem.h
which it includes, at this point:
Queue<Email> mailbox;
I'm guessing, but I find it unlikely that your template Queue
(if it really is a generic class template) needs to know about Email
so you should probably remove #include "EmailSystem.h"
from Queue.h
to solve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With