Math operation on Structure..

hello!
can anyone help me with my problem??
here i want to write a program which is about the ticket reservation..
here my problem..my reservation number can't be increase over the user..
my point is when user1 reserved the ticket = reservation number 1..
user2 = reservation number 2..
so my problem is reservation number 2 didn't appear which means not added..
so anyone can help..thanks :)
here my source code..
https://docs.google.com/document/d/168gR_k_RGEysRKpPpJgrtLm2dLkMr3pbl-5aqc3iWDw/edit
Last edited on
Post your code here, and use code tags please.
none
Last edited on
To count the amount of classes you might want to use a static variable:
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>

struct StaticExample
{
	static int amount;
	int instance;

	StaticExample()
	{
		instance = ++amount;
	}
};

int StaticExample::amount = 0;


int main(void)
{
	StaticExample first;
	StaticExample second;

	std::cout << first.instance << " " << second.instance << '\n';

	return 0;
}
Last edited on
Topic archived. No new replies allowed.