New to classes

This is a discussion on New to classes within the C++ Programming forums, part of the General Programming Boards category; I've looked over this, and never having used classes before am a bit confused on what I'm doing wrong. If ...

New to classes

I've looked over this, and never having used classes before am a bit confused on what I'm doing wrong. If i initialize the counter variable prior to main as part of the class declaration it works fine, otherwise it gives me errors.

Did you try it on the site I gave? If you do it on Windows it may not give this error. Anyways, I fixed the issue by simply changing the name of the class. Seems my prof (who works under windows) told us to use time which is being used elsewhere, perhaps in IOSTREAM I don't know. Here's the error message if anyone is curious,

In function 'int main()':
Line 55: error: expected `;' before 'counter'
compilation terminated due to -Wfatal-errors.

There's this time, so with compilers that happen to include <time.h> from <iostream> you'd get a conflict. This being a standard name and hence in std namespace doesn't seem to help either, since apparently C functions are also available outside the namespace. So the only thing to do is to rename your class (a convention that type names begin with upper-case characters should avoid naming conflicts with the standard) or to put it in its own namespace.

it's funny, I had the exact same problem the first time I tried to learn how to use classes! I suggest you follow the convention mentioned by anon, which is to use the upper-case character for type names (eg Time, LinkedList) - not only it keeps this kind of error away, but your code will look better and easier to understand (at least to me :P)