G
~Gee
Hi,
When I try to compile the following program, I get the following
error:
$ g++ anotherTest.C
anotherTest.C: In function `int main()':
anotherTest.C:47: void value not ignored as it ought to be
What I am trying to do is that I have a global queue. I create an
object of class "testClass" and then add it to the queue. My question
is how do I pop this element from the queue. I am trying to pop the
element using line 47 but it is throwing an error. Any inputs would be
appreciated.
Thanks,
~Gee
1 #include <iostream>
2 #include <queue>
3 #include <list>
4
5 using namespace std;
6 class testClass;
7 class display;
8 std::queue<testClass> Q;
9
10 class testClass
11 {
12 public:
13 inline testClass(int a, int b, int c)
14 {
15 _a = a;
16 _b = b;
17 _c = c;
18 }
19
20 inline string printVals()
21 {
22 cout << "a: " << _a << " b: " << _b << " c: " << _c;
23 }
24
25 private:
26 int _a, _b,_c;
27 };
28
29 class display
30 {
31 public:
32
33 void addToQ()
34 {
35 testClass* obj = new testClass(1, 2, 3);
36 Q.push(*obj);
37 delete obj;
38 }
39 };
40
41 int main()
42 {
43 cout << "begin"<<endl;
44 display* d = new display();
45 d->addToQ();
46
47 testClass* returnedObj = Q.pop();
48 cout << "size: " << Q.size() << endl;
49 returnedObj->printVals();
50 delete d;
51
52 return 0;
53 }
When I try to compile the following program, I get the following
error:
$ g++ anotherTest.C
anotherTest.C: In function `int main()':
anotherTest.C:47: void value not ignored as it ought to be
What I am trying to do is that I have a global queue. I create an
object of class "testClass" and then add it to the queue. My question
is how do I pop this element from the queue. I am trying to pop the
element using line 47 but it is throwing an error. Any inputs would be
appreciated.
Thanks,
~Gee
1 #include <iostream>
2 #include <queue>
3 #include <list>
4
5 using namespace std;
6 class testClass;
7 class display;
8 std::queue<testClass> Q;
9
10 class testClass
11 {
12 public:
13 inline testClass(int a, int b, int c)
14 {
15 _a = a;
16 _b = b;
17 _c = c;
18 }
19
20 inline string printVals()
21 {
22 cout << "a: " << _a << " b: " << _b << " c: " << _c;
23 }
24
25 private:
26 int _a, _b,_c;
27 };
28
29 class display
30 {
31 public:
32
33 void addToQ()
34 {
35 testClass* obj = new testClass(1, 2, 3);
36 Q.push(*obj);
37 delete obj;
38 }
39 };
40
41 int main()
42 {
43 cout << "begin"<<endl;
44 display* d = new display();
45 d->addToQ();
46
47 testClass* returnedObj = Q.pop();
48 cout << "size: " << Q.size() << endl;
49 returnedObj->printVals();
50 delete d;
51
52 return 0;
53 }