Error: expected unqualified-id before '.' token

Good evening. I am doing an assignment for my class. I am using codeblock. My assigment is to implement a circular queue. My code is below, as well the error. From reading previous forum it seems is a syntax error but I cant tell what wrong with that lines.

Error:
E:\CodeBlocks\cirstack.cpp||In function 'int main()':|
E:\CodeBlocks\cirstack.cpp|126|error: expected unqualified-id before '.' token|
E:\CodeBlocks\cirstack.cpp|127|error: expected unqualified-id before '.' token|
E:\CodeBlocks\cirstack.cpp|128|error: expected unqualified-id before '.' token|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 0 seconds) ===|


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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>

using namespace std;

class CircStack
{
    public:
        CircStack(int cap); // stack capacity
        void push(double d); // push new number on stack
        double pop(); // remove and return a double
        double peek(); // return stack top without removing
        int size(); // return how many elements on stack

    private:
        double *data; // pointer to array of doubles
        int capacity; // the size of the array
        int top; // index of next open spot
        int bottom; //index of the deletion
        int count; // number of items on stack
};
//Class Implementation

//Capacity parameter
CircStack::CircStack (int cap)
{
    capacity=cap;

    cout << "The Capacity of the Circular Buffer is: " << capacity << endl;

    //Allocating a pointer to the array (data)
    top = bottom = -1;
    CircStack::capacity = capacity- 1;
    data = new double[cap];
    count = 0;

    for(int i = 0; i <= cap; i++)
        {
    	data[i] = 0;
        }

    //showing staring point
    for ( int i = 0; i < 5; i++ )
        {
            cout << data[i] << " ";
        }

}

//Push number into stack
void CircStack::push(double d)
{
    if (top == 0 && bottom == capacity || top == bottom + 1)
    {
        cout << "Queue is full\n";
    }
	else if (top == -1 && bottom == -1)
    {
	    top = 0;
	    bottom = 0;
	    data[top] = d;
	    count++;
    }
    else if (bottom == capacity)
    {
    	bottom = 0;
    	data[bottom] = d;
    	count++;
    }
    else
    {
    	bottom++;
    	data[bottom] = d;
    	count++;
    }
}

//remove a number
double CircStack::pop()
{

    if (top == -1 && bottom == -1)
    {
        cout << "Queue is empty\n";
    }

    else
    {
        if (top == bottom)
            {
	    data[top] = 0;
	    top = -1;
	    bottom = -1;
	    count--;
            }

        else if (top == capacity)
        {
            data[top] = 0;
            top = 0;
            count--;
        }
        else
        {
	    data[top] = 0;
	    top++;
	    count--;
        }
    }
}

//return top of stack
double CircStack:: peek()
{
    cout << data[4];
}

//return how many number on stack
int CircStack:: size()
{
    cout<< count;
}

int main()
{
    CircStack cap(5);
    CircStack.push(5.0);
    CircStack.size();
    CircStack.peek();

    return 0;
}
Call the function on the variable, not on the class.
1
2
3
4
CircStack cap(5);
cap.push(5.0);
cap.size();
cap.peek();

After you instantiate an object (at line 125) you have to call the methods on the instance. This means

1
2
3
cap.push(...);
cap.size();
...
Thank you. Peter87 and minomic.
Topic archived. No new replies allowed.