On Aug 14, 12:02*pm, Alan Mackenzie <a...@muc.de> wrote:
> Here is a fragment from an old test case in Emacs's C++ Mode:
>
> 1 class CLS {
> 2 * * int i; float f; char *s;
> 3 }
> 4 * * cls_1 /* ; */ (1,
> 5 * * * * * * * * * *1.0,
> 6 * * * * * * * * * *"foo"
> 7 * * * * ),
> 8 * * cls_2 (2, -1.0, "bar");
>
> . *Noting that the bracketing characters on lines 4, 7 and 8 are
> parentheses (not braces), is this coherent C++? *If so, what sort of
> identifiers are "cls_1" and "cls_2"?
>
> At the moment, Emacs's C++ mode is highlighting cls_1 and cls_2 as
> functions. *If the fragment is coherent C++, this might be the wrong
> thing to do. *On the other hand, If the fragment is nonsense, it doesn't
> really matter.
>
> Please, somebody, help me out with this puzzling bit of code. *Thanks in
> advance!
>
> --
> Alan Mackenzie (Nuremberg, Germany).
Sorry it is not a correct C++ fragment; There is no CLS constructor
which takes an int, float and const char * as arguments. The C++
compiler will only generate a the no argument and copy constructor
which respectively takes no arguments and a reference to a CLS
instance, i.e. CLS::CLS() and CLS::CLS(const CLS &). The intent may
have been to do the following
class CLS {
int i, float f, char *s;
// Note the following 3 lines
public:
CLS(int _i, float _f, char *_s): i(_i), f(_f), s(_s){}
} cls_1(1, 1.0, "foo"),
cls_2(2, -1.0, "bar");
|