I have made a struct Queue and now i want an object for Queue but it says it doesn't not have storing capabilities , It works when i try to make it in function it accesses s front and rear
1 2 3 4 5 6 7 8 9 10
struct Queue
{
int items[length];
int front ,rear;
};
Queue q;
q.front=-1;//does not work why??
void Enque(int x)
{
q.front=1;//does work why??
Swap function will not be called.
Sorry but i still don't understand why can't i make global instance of Queue can you ignore Enguue() function and how will be it possible to make an object of Queue and assign -1 to its front member?
You can't put executable code outside of a function.
The swap function there will result in a syntax error, just as your assignment did in the OP.
Sharan123 wrote:
Sorry but i still don't understand why can't i make global instance of Queue can you ignore Enguue() function and how will be it possible to make an object of Queue and assign -1 to its front member?
You can make a global instance of Queue. You cannot assign values to that object outside of a function unless it is part of the initialization of that object.
If you insist on not defining an appropriate constructor: