Jump to content
  • Advertisement
Sign in to follow this  
sharpnova

'basic' Class member initialization question

This topic is 4169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
Just put a semicolon after the closing brace, and it should work:

class X
{
private:
static int num;
}; // put it here

int X::num = 0;


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!