Trying to compile a program and getting an error in the Makefile.win
I am getting this error message:
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
|
Rebuilding whole project...
|
- Project Filename: C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\Queues.dev
- Compiler Name: TDM-GCC 4.9.2 32-bit Release
Building makefile...
--------
- Filename: C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\Makefile.win
Processing makefile...
--------
- Makefile Processor: C:\Program Files\Dev-Cpp\MinGW64\bin\mingw32-make.exe
- Command: mingw32-make.exe -f "C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\Makefile.win" clean all
rm.exe -f Queues/main.o Queues/Queue.o Queues.exe
g++.exe -c Queues/main.cpp -o Queues/main.o -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -m32
In file included from Queues/main.cpp:2:0:
Queues/Queue.h:2:1: error: expected unqualified-id before '{' token
{
^
C:\Documents and Settings\ALISON STUDENT\My Documents\ZolaMndeni\Makefile.win:28: recipe for target 'Queues/main.o' failed
mingw32-make.exe: *** [Queues/main.o] Error 1
Compilation results...
--------
- Errors: 1
- Warnings: 0
- Compilation Time: 3.33s
|
Here is my coding:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
{
struct QueueNode
{
char data;
QueueNode *link;
};
typedef QueueNode *QueueNodePtr;
class Queue
{
public:
Queue();
Queue(const Queue &aQueue);
~Queue();
void add(char item);
char remove();
bool empty() const;
private:
QueueNodePtr front;
QueueNodePtr back;
}
};
|
The implementation:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
//THE IMPLEMENTATION
#include<iostream>
#include "Queue.h"
using namespace std;
#include<cstdlib>
#include<cstddef>
{
Queue::Queue() : front(NULL), back(NULL)
{
}
Queue::Queue(const Queue &aQueue) {
if(aQueue.empty())
front = back = NULL;
else {
QueueNodePtr temp_ptr_old = aQueue.front;
QueueNodePtr temp_ptr_new;
back = new QueueNode;
back->data = temp_ptr_old->data;
back->link = NULL;
front = back; //First node created and filled with data
temp_ptr_old = temp_ptr_old->link; // temp_ptr_old now
//points to second node or NULL if there is
//no second node
while(temp_ptr_old != NULL)
{
temp_ptr_new = new QueueNode;
temp_ptr_new->data = temp_ptr_old->data;
temp_ptr_new->link = NULL;
back->link = temp_ptr_new;
back = temp_ptr_new;
temp_ptr_old = temp_ptr_old->link;
}
}
}
Queue::~Queue()
{
char next;
while(!empty())
next = remove(); //remove calls delete
}
bool Queue::empty() const
{
(back == NULL);
}
void Queue::add(char item)
{
if(empty())
{
front = new QueueNode;
front->data = item;
front->link = NULL;
back = front;
}
else
{
QueueNode_ptr temp_ptr;
temp_ptr = new QueueNode;
temp_ptr->data = item;
temp_ptr->link = NULL;
back->link = temp_ptr;
back = temp_ptr;
}
}
char Queue::remove()
{
if(empty())
{
cout <<"Error: Removing from an empty queue.\n";
exit(1);
}
char result = front->data;
QueueNodePtr discard;
discard = front;
front = front->link;
if(front == NULL) //if you remove the last node
back = NULL;
delete discard;
return result;
}
}
}
|
main
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
|
#include <iostream>
#include "Queue.h"
using namespace std;
int main()
{
Queue q;
char next , ans;
do {
cout <<"Enter a word: ";
cin.get(next);
while (next != '\n') {
q.add(next);
cin.get(next);
}
cout <<"You entered:: ";
while (!q.empty())
cout << q.remove();
cout << endl;
cout <<"Again?(y/n) : ";
cin >> ans;
cin.ignore(10000, '\n') ;
} while(ans !='n' && ans != 'N');
return 0;
}
|
You have some misplaced curly braces.
First file: line 2, 22
Second: line 7, 80, 81
I suggest an uniform indentation. This way it is hard to see which opening brace belongs to which closing. brace
Were you trying to create a namespace?
Like
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
|
#include <iostream>
namespace myq {
struct QueueNode
{
char data;
QueueNode *link;
};
typedef QueueNode *QueueNodePtr;
class Queue
{
public:
Queue();
Queue(const Queue &aQueue);
~Queue();
void add(char item);
char remove();
bool empty() const;
private:
QueueNodePtr front;
QueueNodePtr back;
}
};
|
Also, your empty() function doesn't return a result.
Its all sorted out now. There was a problem about the curly brackets.
Thank you all GOOD PEOPLE!!!!
Topic archived. No new replies allowed.