On Tue, 30 Oct 2001, Shailesh Dargude wrote:

>   I get some linker error, can anybody enlighten me on this.
>
>   CODE: foo.cc

It seems me that the solution posted earlier by declaring function as
static incorrect as I am unable to compile that.

Here is my solution using separate file ( which is actual practice for all
practical / real programs ) How to do in a single file, I would like to
listen from some list member.

st.h
========

  # include <iostream.h>
  class foo {
      private:
          static int counter;
      public :
         foo ();
         int get_counter () ;
     };

st.cc
=========

  # include <iostream.h>
  # include "st.h"
         int foo::counter;
         foo::foo () { counter++;}
         int foo::get_counter ()
         { return counter; }

stMain.cc
=============

  # include <iostream.h>
  # include "st.h"
  int main () {
      foo f1,f2,f3;
         cout <<f1.get_counter();
         cout <<f2.get_counter();
         cout <<f3.get_counter();
         return 0;
  }

compile using

g++ stMain.cc st.cc

HTH

H.S.Rai



_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to