On 9 Jun 2003 19:22:54 -0700, "Rajesh" <rvenk...@pacbell.net> wrote in
borland.public.cpp.borlandcpp:
Quote
> Hi Everyone,
> I am learning C++. Entered this below program. Using Borland C++ Compiler (5.5.1 for Win32), Linker (5.00). I get errors. Can someone tell me, what exactly is wrong. Thanks in advance, Rajesh.
First, you are in the wrong newsgroup, although the way they name
these groups does not make it easy to see that. Your compiler is
supported in news:borland.public.cppbuilder.commandlinetools, since it
is the command line compiler from C++ Builder.
Quote
> Error message I get is : Unresolved external 'foo::count'
> // program begin
> #include <iostream.h>
There has been an ANSI/ISO standard for C++ for almost four years now,
drop the obsolete headers and learn the real language:
#include <iostream>
using namespace std;
Quote
> class foo
> {
> private:
> static int count;
> public:
> foo()
> {
> count++;
> }
> int getcount()
> {
> return count;
> }
> };
The definition of a class does not actually create or instantiate any
objects. It does not create any members of the class, and it does not
create the one necessary object of each class static variable. You
need to define that in a source file outside the class:
int foo::count;
"void main()" has never been legal in C++ (or C either, for that
matter). Both languages require that main() be defined with a return
type of int in a hosted environment. If you turn up the compiler
warning levels, it would tell you that.
int main()
Quote
> {
> foo f1, f2, f3;
> cout << "\nCount is " << f1.getcount();
> cout << "\nCount is " << f2.getcount();
> cout << "\nCount is " << f3.getcount();
> }
> // program end
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq