'basic' Class member initialization question

Started by
0 comments, last by nmi 16 years, 12 months ago

class X
  {
    private:
      static int num;
  }

int X::num = 0;


My instructor was able to compile this in class no problem. He's using the same exact compiler I am as well. (it's possible i might have made a slight error transcribing the code he was writing to paper though, which would explain my problem) But I get a lot of errors when attempting to do this. x.cpp:7: semicolon missing after declaration of `X' x.cpp:7: extraneous `int' ignored x.cpp:7: conflicting types for `X X::num' x.cpp:4: previous declaration as `int X::num' x.cpp: In static member function `void __static_initialization_and_destruction_0(int, int)': x.cpp:7: conversion from `int' to non-scalar type `X' requested What exactly am I doing wrong here? What I want is (in my file where I declare all my member functions for X), to initialize the static member "num" to 0, so it would be 0 for every instance of X. I have a feeling I'm misunderstanding something very basic here. EDIT: Thank you nmi. I should have looked over my notes on classes better. [Edited by - sharpnova on April 21, 2007 1:26:28 AM]
Everyone hates #1.That's why a lot of idiots complain about WoW, the current president, and why they all loved google so much when it was new.Forget the fact that WoW is the greatest game ever created, our president rocks and the brainless buffons of America care more about how articulate you are than your decision making skills, and that google supports adware, spyware, and communism.
Advertisement
Just put a semicolon after the closing brace, and it should work:
class X  {    private:      static int num;  }; // put it hereint X::num = 0;

This topic is closed to new replies.

Advertisement