Help with a class. Any advice appreciated.
Hi,
I don't know where my program is going wrong, but I can't get it to compile. I have 3 files, dq.h, dq.cpp and dqtester.cpp
I have no problems with adding functions to the linked list once its done, I just need to class to compile so I can add functions to it. I have no idea where I am going wrong. If someone can point out where I have gone wrong I would appreciate it, I really need this to compile so I can start adding functions and making the queue work.
dq.h
Code:
#include <iostream>
struct node
{
int item;
node* next;
};
class dqueue
{
public:
dqueue( );
bool empty( );
private:
int size;
node* front;
};
#include "dq.cpp"
#endif
dq.cpp
Code:
#include "dq.h"
dqueue::dqueue( )
{
front = NULL;
size = 0;
}
bool dqueue::empty()
{
if (size == )
return true;
return false;
}
dqtester.cpp
Code:
#include <iostream.h>
#include "dq.h"
void main()
{
cout<<"Yes!";
}
I am really bad with classes but I am trying to learn. I have been mucking around with this, rewriting it over and over again for hours. Its 2.30 am. If someone can point out where I have gone wrong I would appreciate it. I don't know if I am meant to declare the node struct in a different file then the .h or if I have a syntax error or logic error but I am pulling my hair out and I can't take it anymore :(
I know some of you guys are very good at C++ - If you can give me any advice about getting good at classes I would be grateful. I know they are important, I just can't get good at them no matter what I do. I guess I just need practise.
Re: Help with a class. Any advice appreciated.
Also,
Quote:
Originally posted by Michael_Bray
You should never be #include'ing .c or .cpp files, only .h files.
As long as the .cpp file is a part of your project, it will be compiled.