Alf P. Steinbach wrote:[color=blue]
> *
amparikh@gmail.com:[color=green]
> > I have some test code which demonstrates the problem. I know I could
> > solve this by just returning a pointer, but I better use a reference.
> >
> > In real code, what I actually want to return is a reference to an array
> > of function pointers. But the code below is good enough to show the
> > problem.
> >
> > Thanks.
> >
> > #define MAX_DEC 11
> >
> > static char (&MyFunc())[MAX_DEC]
> > {
> > static char init[] = "Hihowareya";
> > return init;
> > }
> >
> > class A
> > {
> > private :
> > char (&Ptr)[MAX_DEC];
> > public:
> > A() : Ptr(::MyFunc())
> > {
> > }
> >
> > };
> >
> > int main()
> > {
> > A a;
> > }
> >
> > The error I get is "'A::Ptr' : initialization of reference member
> > requires a temporary variable"[/color]
>
> Technically this is a compiler error; the code should compile, and does
> compile with g++ and Comeau online.
>
> However, I'd count this compiler error as a blessing... Don't /do/ this
> kind of thing!
>
> At the very least, put your array inside a struct (that will probably
> make it compile, and also get rid of the lack of a type name). And you
> shouldn't really have reference members, they're mostly Evil. But most
> of all, unless you're interfacing to C code, an array of function
> pointers says you're missing a class with virtual functions, which
> should be used instead -- this is C++, and the replacement of arrays
> of function pointers, with classes, is the main ++ in C++.[/color]
Actually they are pointers to static CreateInstance Functions of
different classes (denoting different h/w types supported) that are
supported.
and the class where this is implemented does the abstraction.
[color=blue]
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?[/color]