Topic: Class templates and incomplete classes


Author: bard@cutter.ssd.loral.com (James Woodyatt)
Date: Wed, 8 Apr 1992 00:08:27 GMT
Raw View
My compiler (GCC-2.1) complains about the following code by going down
on a segmentation fault (which I figure is enough cause to report it as
a bug), but I have reservations about the validity of the code.

Is this legal? I'm trying to declare a template class with an incomplete
class as the template's parameter.

-------------------------------------------------------------------------
template<class T>
class Foo
{
    Method method;

  public:
    typedef void (T::*Method)();

    Foo(Method m) : method(m)  { }
    void foo() { (*method)(); }
};


class Bar
{
  public:
    static Foo<Bar> foo; // Instantiate a template class on an incomplete class

    void alpha()  { }
    void beta()   { }
};


Bar::foo(&Bar::alpha);


int main()
{
    Foo f;

    f.foo();
    return 0;
}


--
James Woodyatt  Space Systems/Loral   Palo Alto, CA   bard@cutter.ssd.loral.com

``And when he dreamed his ears drooled thirty weight engine oil
He took personality tests and stapled them to his lower lip''
        --Stan Ridgway,
          `Jack Talked (Like A Man On Fire)'




Author: bard@cutter.ssd.loral.com (James Woodyatt)
Date: 8 Apr 92 02:57:34 GMT
Raw View
In article <1992Apr8.000827.20812@wdl.loral.com>, bard@cutter.ssd.loral.com (James Woodyatt) writes:
|> int main()
|> {
|>     Foo f;
|>
|>     f.foo();
|>     return 0;
|> }

I feel dumb. I should have written this:

int main()
{
    Foo<Bar> f& = foo;

    f.foo();
    return 0;
}

It doesn't change the substance of my question though.

Sorry about the confusion. I didn't notice the obsolete code because my
compiler was crashing on code upstream of this.


--
James Woodyatt  Space Systems/Loral   Palo Alto, CA   bard@cutter.ssd.loral.com

``And when he dreamed his ears drooled thirty weight engine oil
He took personality tests and stapled them to his lower lip''
        --Stan Ridgway,
          `Jack Talked (Like A Man On Fire)'