askque
askque

Reputation: 319

define private member variables in single line

Last class my instructor said that you can't define private member variables in a single line like

private:
    int x,y;

It doesn't make any sense why he said like that. Could you explain is there any reasonable reason?

Upvotes: 0

Views: 229

Answers (1)

utnapistim
utnapistim

Reputation: 27365

Sure you can; You just shouldn't.

The definition of multiple variables on the same line can cause confusion in a few cases (which is probably the reason your instructor told you that).

Ambiguity example (important to know when you learn c++, but also avoided by convention, in most production code bases I've worked in):

int* a, b;

You would expect here for a and b to be pointers, but instead, the definition above is equivalent to:

int *a;
int b;

Upvotes: 4

Related Questions