Can Someone help on this it would be grateful

Hi

Below is my code

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
 
using namespace std;
 
 
    template <class T>
 
class OrderedCollection {
// =================
 
const int capacity_;
int size_; //number of elements
T **buffer;
 
public:
OrderedCollection(int size = 100) : capacity_(size),
buffer(new T*[size]), size_(0){}
 
OrderedCollection(const OrderedCollection<T> & c):
capacity_(c.capacity_), size_(c.size_), buffer(new T*[c.capacity_])
{
for(int i = 0; i < capacity_; i ++)
buffer[i] = c.buffer[i];
}
 
~OrderedCollection() {delete [] buffer; }
 
 
int size() {return size_;}; //answer number of elements
OrderedCollection<T> & add( T & element);
OrderedCollection<T> & addLast( T & element);
OrderedCollection<T> & addFirst( T & element);
T & removeLast();
T & removeFirst();
int remove(const T & element);
 
void printOn(ostream & out) {
for (int i = 0; i < size_; i++)
cout << *buffer[i] << "\n";
}
 
};
 
template <class T>
OrderedCollection<T> & OrderedCollection<T>::add( T & element){
if(size_ < capacity_)
buffer[size_++] = &element;
return *this;
}
 
template <class T>
OrderedCollection<T> & OrderedCollection<T>::addLast( T & element){
return add(&element);
}
 
template <class T>
OrderedCollection<T> & OrderedCollection<T>::addFirst( T & element){
if(size_ < capacity_){
for (int i = size_; i>0; i--)
buffer[i] = buffer[i-1];
buffer[0] = &element;
size_++;
}
return *this;
}
 
template <class T>
T & OrderedCollection<T>::removeLast(){
return * (buffer[--size_]);
}
 
template <class T>
T & OrderedCollection<T>::removeFirst(){
T* temp = buffer[0];
for(int i = 0; i<size_ - 1; i++)
buffer[i] = buffer[i + 1];
size_--;
return * temp;
}
 
template <class T>
int OrderedCollection<T>::remove(const T & item){
//remove first occurence of element == item
//return 1 if element was found and removed and 0 otherwise
int found = 0;
for(int i = 0; i<size_; i++) {
if((*buffer[i] == item) && !found) found = 1;
buffer[i] = buffer[i + found];
}
size_ -= found;
return found;
 
}
 
template <class T>
ostream & operator<<(ostream & out, OrderedCollection<T> & collection) {
collection.printOn(out);
return out;
}


i doesn't know where i went wrong, i am using this site to compile it http://ideone.com/

but it is spitting out an error

/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status

for this is also tried

using

-stdlib=libc++;

but again it showed me an error

prog.cpp:4:1: error: expected unqualified-id before ‘-’ token

so i just tried by eliminating the '-' again an error

prog.cpp:4:1: error: ‘stdlib’ does not name a type


please let me know what can i do....

Thanks in advance for your help.

Is this the whole program?
I don't see anything on line 4.
Why not paste the whole program, so that we can point out the line number where the error is.
I think this is not your full program.I dont see main function itself in this
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
 
using namespace std;
-stdlib=libc++;
 
    template <class T> class OrderedCollection {
// =================
 
const int capacity_;
int size_; //number of elements
T **buffer;
 
public:
OrderedCollection(int size = 100) : capacity_(size),
buffer(new T*[size]), size_(0){}
 
OrderedCollection(const OrderedCollection<T> & c):
capacity_(c.capacity_), size_(c.size_), buffer(new T*[c.capacity_])
{
for(int i = 0; i < capacity_; i ++)
buffer[i] = c.buffer[i];
}
 
~OrderedCollection() {delete [] buffer; }
 
 
int size() {return size_;}; //answer number of elements
OrderedCollection<T> & add( T & element);
OrderedCollection<T> & addLast( T & element);
OrderedCollection<T> & addFirst( T & element);
T & removeLast();
T & removeFirst();
int remove(const T & element);
 
void printOn(ostream & out) {
for (int i = 0; i < size_; i++)
cout << *buffer[i] << "\n";
}
 
};
 
template <class T>
OrderedCollection<T> & OrderedCollection<T>::add( T & element){
if(size_ < capacity_)
buffer[size_++] = &element;
return *this;
}
 
template <class T>
OrderedCollection<T> & OrderedCollection<T>::addLast( T & element){
return add(&element);
}
 
template <class T>
OrderedCollection<T> & OrderedCollection<T>::addFirst( T & element){
if(size_ < capacity_){
for (int i = size_; i>0; i--)
buffer[i] = buffer[i-1];
buffer[0] = &element;
size_++;
}
return *this;
}
 
template <class T>
T & OrderedCollection<T>::removeLast(){
return * (buffer[--size_]);
}
 
template <class T>
T & OrderedCollection<T>::removeFirst(){
T* temp = buffer[0];
for(int i = 0; i<size_ - 1; i++)
buffer[i] = buffer[i + 1];
size_--;
return * temp;
}
 
template <class T>
int OrderedCollection<T>::remove(const T & item){
//remove first occurence of element == item
//return 1 if element was found and removed and 0 otherwise
int found = 0;
for(int i = 0; i<size_; i++) {
if((*buffer[i] == item) && !found) found = 1;
buffer[i] = buffer[i + found];
}
size_ -= found;
return found;
 
}
 
template <class T>
ostream & operator<<(ostream & out, OrderedCollection<T> & collection) {
collection.printOn(out);
return out;
}


prog.cpp:4:1: error: expected unqualified-id before ‘-’ token
Last edited on
What are you trying to accomplish with the following line?

stdlib=libc++;


What are you trying to accomplish with the following line?

i just google it find out what can i do to run this pgm successfully....if any one can help....it would be really thankful.
i just google it find out what can i do to run this pgm successfully....if any one can help....it would be really thankful.

That line is not legal C++. It looks like a compiler option to me - I don't think you read the advice properly!
The problem with your code, other that the line indicated is not valid, is that your program doesn't have a main() function. Every valid C/C++ program must have a function named main().
Topic archived. No new replies allowed.