* Ossama Othman:
> Something like the following should be a good smoke test:
> 
>   class Foo
>   {
>    public:
>      Foo (void) : bar_ (0) { }
>      virtual ~Foo (void) { }
>      virtual int bar (void) { return this->bar_; }
>    private:
>      int bar_;
>   };
> 
>   int main (int, char *[])
>   {
>    Foo fnord;
>    int a = fnord.bar ();
>    return a;
>   }

* Olly Betts:
> Just noticed a problem with this.  If you compile it with:
> 
> gcc -o test test.cc
> 
> You get a working executable called test.

The reason for this is that gcc automatically goes into C++ "mode"
when it sees the .cc extension. You need to call gcc with the "-x"
option to explicitly set it to be "C only":

$ gcc -x c -o test test.cc

will yield

test.cc:1: parse error before `Foo'
test.cc:2: syntax error before `{'
test.cc:6: syntax error before `int'
test.cc: In function `bar':
test.cc:6: `this' undeclared (first use in this function)
[snip]


BTW, I second Ossama's arguments for not using a library function. The
C++ test code looks good to me.

Regards,
Morten

Reply via email to