I am working with fifo module...I actually found the basic code on DaniWeb, just made a few changes to it...
There are 2 main sources...first one is called fifoqueue which consists of basic fifo functions i.e. qu, dequ, isEmpty and a couple more...the second one is called packetstructure which is the basic structure of a packet I want to give as my input...
Here's the entire code...
fifoqueue.h
#ifndef FIFOQUEUE_H
#define FIFOQUEUE_H
#include <iostream>
#include "packetstructure.cpp"
using namespace std;
#define SIZE 20
class QueueClass
{
packet queue[SIZE];
int head, tail;
public:
QueueClass(int, int);
~QueueClass() {};
void qu(packet chunk);
packet dequ();
int size();
int isEmpty();
int charToIntArrays(char);
int charToIntPointers(char);
};
#endif
fifoqueue.cpp
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#include "fifoqueue.h"
QueueClass::QueueClass(int a, int b)
{
head = a;
tail = b;
}
void QueueClass::qu(packet chunk)
{
if(tail+1==head || (tail+1==SIZE && !head))
{
cout << "Queue is full\n";
return;
}
tail++;
if(tail==SIZE) tail = 0;
queue[tail] = chunk;
}
packet QueueClass::dequ()
{
if(head==tail)
{
cout << "Queue is empty\n";
return NULL;
}
head++;
if(head==SIZE) head = 0;
return 0;
}
int QueueClass::size()
{
int j = 0;
for(; j<tail; j++) {}
return j;
}
int QueueClass::isEmpty()
{
if(head == tail)
{
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
int charToIntArrays(char ch[])
{
int value = atoi(&ch[0]);
return value;
}
int charToIntPointers(char *ch)
{
int value=atoi(ch);
return value;
}
#endif
#endif
packetstructure.cpp
#include <iostream>
using namespace std;
class header
{
public:
unsigned char offset[3];
unsigned char forwardingLabel[64];
unsigned char trailerOffset[3];
unsigned char privateFrameLimit[3];
unsigned char publicSize[3];
};
class content
{
public:
unsigned char * payload;
};
class trailer
{
public:
unsigned char * trailer1;
unsigned char * trailer2;
};
class packet
{
public:
header myHeader;
content myContent;
trailer myTrailer;
};
I am getting these 4 errors (I am commenting them in main)...
main.cpp
#include <iostream>
#include "fifoqueue.cpp"
using namespace std;
int main()
{
QueueClass queue1(1,1);
/*Error1:- error C2065: 'QueueClass' : undeclared identifier;
Error2:- error C2146: syntax error: missing ';' before identifier 'queue1';
Error3:- error C3861: 'queue1': identifier not found*/
cout<<"1 if queue is empty, 0 if queue is full. Result:"<<queue1.isEmpty()<<endl; /*Error4:- error C2228: left of '.isEmpty' must have class/struct/union*/
return 0;
}
The funny thing is I was not getting these errors earlier. And all the changes that I have made to the code should not have affected these lines of codes at all.
I am not sure if this is going to help- When I started the program Visual Studio gave this message "The line endings in the following file are not consistent. Do you want to normalize the line endings?". I was not sure how to normalise a file. But I haven't got the message again.
I am unable to resolve them. Can someone please help.