Re: A question about TC++PL

Discussion in 'C++' started by Paul Bibbings, Jun 15, 2010.

  1. Chen Zhuhui <> writes:

    > Dear All,
    >
    > I'm reading appendix C.13.8.3 in TC++PL special ed. and it says:
    >
    > "
    > The definition of "instantiation point" implies that a template
    > parameter can never be bound to a local name or a class member. For
    > example:
    >
    > void f()
    > {
    > struct X { /* ... */ }; // local structure
    > vector<X> v; // error: cannot use local structure as
    > // template parameter
    > // ...
    > }
    >
    > .......
    > "
    >
    > So if I haven't misunderstood something, the example is showing about "a
    > template parameter can never be bound to a local name". But how about "a
    > class member"? I cannot figure myself out an example of this
    > situation. I've tried:
    >
    > struct classA
    > {
    > struct classB { };
    > typedef int classC;
    >
    > void classAF()
    > {
    > vector<classB> v1; // 1
    > vector<classC> v2; // 2
    > }
    > };
    >
    > void f()
    > {
    > vector<classA::classB> v1; // 3
    > vector<classA::classC> v2; // 4
    > }
    >
    > None of 1, 2, 3 or 4 yields an error.
    >
    > So, what does "a class member" refer to? Or, how can I try to bind "a
    > class member" to a template parameter? (and then the compiler will kick
    > me with an error :p)


    I don't know this for a fact (in the sense that I don't know whether it
    is what Stroustrup intends) but I wonder if he is referring to a class
    member of the class that is being instantiated, as in:

    19:49:50 Paul Bibbings@JIJOU
    /cygdrive/d/CPPProjects/CLCPP $cat inst_point.cpp
    // file: inst_point.cpp

    template<typename T>
    struct A {
    struct B { };
    };

    int main()
    {
    A<A::B> a1;
    }

    19:49:57 Paul Bibbings@JIJOU
    /cygdrive/d/CPPProjects/CLCPP $i686-pc-cygwin-gcc-4.4.3 -c
    inst_point.cpp
    inst_point.cpp: In function ¡®int main()¡¯:
    inst_point.cpp:10: error: template argument 1 is invalid
    inst_point.cpp:10: error: invalid type in declaration before ¡®;¡¯
    token

    19:50:11 Paul Bibbings@JIJOU
    /cygdrive/d/CPPProjects/CLCPP $

    Regards

    Paul Bibbings
    Paul Bibbings, Jun 15, 2010
    #1
    1. Advertising

  2. Paul Bibbings <> writes:

    > Chen Zhuhui <> writes:
    >
    >> Dear All,
    >>
    >> I'm reading appendix C.13.8.3 in TC++PL special ed. and it says:
    >>
    >> "
    >> The definition of "instantiation point" implies that a template
    >> parameter can never be bound to a local name or a class member. For
    >> example:
    >>
    >> void f()
    >> {
    >> struct X { /* ... */ }; // local structure
    >> vector<X> v; // error: cannot use local structure as
    >> // template parameter
    >> // ...
    >> }
    >>
    >> .......
    >> "
    >>
    >> So if I haven't misunderstood something, the example is showing about "a
    >> template parameter can never be bound to a local name". But how about "a
    >> class member"? I cannot figure myself out an example of this
    >> situation. I've tried:
    >>
    >> struct classA
    >> {
    >> struct classB { };
    >> typedef int classC;
    >>
    >> void classAF()
    >> {
    >> vector<classB> v1; // 1
    >> vector<classC> v2; // 2
    >> }
    >> };
    >>
    >> void f()
    >> {
    >> vector<classA::classB> v1; // 3
    >> vector<classA::classC> v2; // 4
    >> }
    >>
    >> None of 1, 2, 3 or 4 yields an error.
    >>
    >> So, what does "a class member" refer to? Or, how can I try to bind "a
    >> class member" to a template parameter? (and then the compiler will kick
    >> me with an error :p)

    >
    > I don't know this for a fact (in the sense that I don't know whether it
    > is what Stroustrup intends) but I wonder if he is referring to a class
    > member of the class that is being instantiated, as in:
    >
    > 19:49:50 Paul Bibbings@JIJOU
    > /cygdrive/d/CPPProjects/CLCPP $cat inst_point.cpp
    > // file: inst_point.cpp
    >
    > template<typename T>
    > struct A {
    > struct B { };
    > };
    >
    > int main()
    > {
    > A<A::B> a1;
    > }
    >
    > 19:49:57 Paul Bibbings@JIJOU
    > /cygdrive/d/CPPProjects/CLCPP $i686-pc-cygwin-gcc-4.4.3 -c
    > inst_point.cpp
    > inst_point.cpp: In function ¡®int main()¡¯:
    > inst_point.cpp:10: error: template argument 1 is invalid
    > inst_point.cpp:10: error: invalid type in declaration before ¡®;¡¯
    > token
    >
    > 19:50:11 Paul Bibbings@JIJOU
    > /cygdrive/d/CPPProjects/CLCPP $
    >


    Just to add what I see as the reason for this failure, because I omitted
    it from the above post.

    Given the definition of the template class A, the attempted
    instantiation:

    A<A::B> a1;

    won't do because the template argument is missing *its* required
    template arguments for A. But how are these to be provided, since we
    immediately enter an infinitely recursive nesting of the form:

    A<A<A<...::B>::B>::B> a1;

    giving an instance where "a template parameter can never be bound ... to
    a class member." The same would apply to an attempt to use a data
    member for a non-template parameter:

    template<int I>
    struct C
    {
    static const int i = 1;
    };

    int main()
    {
    int i = C<C<C<...::i>::i>::i>::i;
    }

    or a member typedef:

    template<typename T>
    struct D
    {
    typedef int type;
    };

    int main()
    {
    D<D<D<...::type>::type>::type> d1;
    }

    Regards

    Paul Bibbings
    Paul Bibbings, Jun 16, 2010
    #2
    1. Advertising

  3. Paul Bibbings

    mingze zhang Guest

    On Jun 16, 7:58 am, Paul Bibbings <> wrote:
    > Paul Bibbings <> writes:
    > > Chen Zhuhui <> writes:

    >
    > >> Dear All,

    >
    > >> I'm reading appendix C.13.8.3 in TC++PL special ed. and it says:

    >
    > >> "
    > >> The definition of "instantiation point" implies that a template
    > >> parameter can never be bound to a local name or a class member. For
    > >> example:

    >
    > >> void f()
    > >> {
    > >>     struct X { /* ... */ };  // local structure
    > >>     vector<X> v;             // error: cannot use local structure as
    > >>                              // template parameter
    > >>     // ...
    > >> }

    >
    > >> .......
    > >> "

    >
    > >> So if I haven't misunderstood something, the example is showing about "a
    > >> template parameter can never be bound to a local name". But how about "a
    > >> class member"? I cannot figure myself out an example of this
    > >> situation. I've tried:

    >
    > >> struct classA
    > >> {
    > >>    struct classB { };
    > >>    typedef int classC;

    >
    > >>    void classAF()
    > >>    {
    > >>       vector<classB> v1;  // 1
    > >>       vector<classC> v2;  // 2
    > >>    }
    > >> };

    >
    > >> void f()
    > >> {
    > >>    vector<classA::classB> v1;  // 3
    > >>    vector<classA::classC> v2;  // 4
    > >> }

    >
    > >> None of 1, 2, 3 or 4 yields an error.

    >
    > >> So, what does "a class member" refer to? Or, how can I try to bind "a
    > >> class member" to a template parameter? (and then the compiler will kick
    > >> me with an error :p)

    >
    > > I don't know this for a fact (in the sense that I don't know whether it
    > > is what Stroustrup intends) but I wonder if he is referring to a class
    > > member of the class that is being instantiated, as in:

    >
    > >    19:49:50 Paul Bibbings@JIJOU
    > >    /cygdrive/d/CPPProjects/CLCPP $cat inst_point.cpp
    > >    // file: inst_point.cpp

    >
    > >    template<typename T>
    > >    struct A {
    > >       struct B { };
    > >    };

    >
    > >    int main()
    > >    {
    > >       A<A::B> a1;
    > >    }

    >
    > >    19:49:57 Paul Bibbings@JIJOU
    > >    /cygdrive/d/CPPProjects/CLCPP $i686-pc-cygwin-gcc-4.4.3 -c
    > >       inst_point.cpp
    > >    inst_point.cpp: In function int main() :
    > >    inst_point.cpp:10: error: template argument 1 is invalid
    > >    inst_point.cpp:10: error: invalid type in declaration before ;
    > >       token

    >
    > >    19:50:11 Paul Bibbings@JIJOU
    > >    /cygdrive/d/CPPProjects/CLCPP $

    >
    > Just to add what I see as the reason for this failure, because I omitted
    > it from the above post.
    >
    > Given the definition of the template class A, the attempted
    > instantiation:
    >
    >    A<A::B> a1;
    >
    > won't do because the template argument is missing *its* required
    > template arguments for A.  But how are these to be provided, since we
    > immediately enter an infinitely recursive nesting of the form:
    >
    >    A<A<A<...::B>::B>::B> a1;
    >
    > giving an instance where "a template parameter can never be bound ... to
    > a class member."  The same would apply to an attempt to use a data
    > member for a non-template parameter:
    >
    >    template<int I>
    >    struct C
    >    {
    >       static const int i = 1;
    >    };
    >
    >    int main()
    >    {
    >       int i = C<C<C<...::i>::i>::i>::i;
    >    }
    >
    > or a member typedef:
    >
    >    template<typename T>
    >    struct D
    >    {
    >       typedef int type;
    >    };
    >
    >    int main()
    >    {
    >       D<D<D<...::type>::type>::type> d1;
    >    }
    >
    > Regards
    >
    > Paul Bibbings


    Just to inform people the news that the 4th version of TC++PL is
    already on the schedule and would probably be ready in 6 months after
    the C++0x standard is settled.

    This is the response from Professor Bjarne Stroustrup:

    Bjarne Stroustrup to me
    show details Jun 3 (13 days ago)
    mingze zhang wrote:


    On Mar 3 1998, 4:00 pm, (Bjarne Stroustrup)
    wrote:

    (Burke Haworth) writes:

    >Stroustrup's3rd edition of "The C++ Programming Language" has
    > disappeared from the book stores and a check at the Chapters here
    > shows it as delisted. Is there a fourth edition on the way?


    My 3rd edition has been out for only about half a year and should be
    good for at least another five or six years.

    I don't know what "check at the Chapters" means, but my 3rd is in
    stock
    at Addison-Wesley. Maybe your bookstores have gotten their files
    messed
    up?
    Maybe they got it confused with my 2nd edition?

    - Bjarne

    BjarneStroustrup, AT&T Labs,http://www.research.att.com/~bs

    [ Send an empty e-mail to for info ]
    [ about comp.lang.c++.moderated. First time posters: do this! ]


    I want to ask the same question.
    Now it is 27th May 2010 and C++1x standard has already been fixed. I
    think that it is also the right time to ask it.


    It's the right time t ask. C++0x is probably 12 months away and the
    4th edition at least 18 months away - it will be a massive piece of
    work.
    mingze zhang, Jun 16, 2010
    #3
  4. Paul Bibbings

    X Guest

    On Jun 16, 7:58 am, Paul Bibbings <> wrote:
    > Paul Bibbings <> writes:
    > > Chen Zhuhui <> writes:

    >
    > >> Dear All,

    >
    > >> I'm reading appendix C.13.8.3 in TC++PL special ed. and it says:

    >
    > >> "
    > >> The definition of "instantiation point" implies that a template
    > >> parameter can never be bound to a local name or a class member. For
    > >> example:

    >
    > >> void f()
    > >> {
    > >>     struct X { /* ... */ };  // local structure
    > >>     vector<X> v;             // error: cannot use local structure as
    > >>                              // template parameter
    > >>     // ...
    > >> }

    >
    > >> .......
    > >> "

    >
    > >> So if I haven't misunderstood something, the example is showing about "a
    > >> template parameter can never be bound to a local name". But how about "a
    > >> class member"? I cannot figure myself out an example of this
    > >> situation. I've tried:

    >
    > >> struct classA
    > >> {
    > >>    struct classB { };
    > >>    typedef int classC;

    >
    > >>    void classAF()
    > >>    {
    > >>       vector<classB> v1;  // 1
    > >>       vector<classC> v2;  // 2
    > >>    }
    > >> };

    >
    > >> void f()
    > >> {
    > >>    vector<classA::classB> v1;  // 3
    > >>    vector<classA::classC> v2;  // 4
    > >> }

    >
    > >> None of 1, 2, 3 or 4 yields an error.

    >
    > >> So, what does "a class member" refer to? Or, how can I try to bind "a
    > >> class member" to a template parameter? (and then the compiler will kick
    > >> me with an error :p)

    >
    > > I don't know this for a fact (in the sense that I don't know whether it
    > > is what Stroustrup intends) but I wonder if he is referring to a class
    > > member of the class that is being instantiated, as in:

    >
    > >    19:49:50 Paul Bibbings@JIJOU
    > >    /cygdrive/d/CPPProjects/CLCPP $cat inst_point.cpp
    > >    // file: inst_point.cpp

    >
    > >    template<typename T>
    > >    struct A {
    > >       struct B { };
    > >    };

    >
    > >    int main()
    > >    {
    > >       A<A::B> a1;
    > >    }

    >
    > >    19:49:57 Paul Bibbings@JIJOU
    > >    /cygdrive/d/CPPProjects/CLCPP $i686-pc-cygwin-gcc-4.4.3 -c
    > >       inst_point.cpp
    > >    inst_point.cpp: In function int main() :
    > >    inst_point.cpp:10: error: template argument 1 is invalid
    > >    inst_point.cpp:10: error: invalid type in declaration before ;
    > >       token

    >
    > >    19:50:11 Paul Bibbings@JIJOU
    > >    /cygdrive/d/CPPProjects/CLCPP $

    >
    > Just to add what I see as the reason for this failure, because I omitted
    > it from the above post.
    >
    > Given the definition of the template class A, the attempted
    > instantiation:
    >
    >    A<A::B> a1;
    >
    > won't do because the template argument is missing *its* required
    > template arguments for A.  But how are these to be provided, since we
    > immediately enter an infinitely recursive nesting of the form:
    >
    >    A<A<A<...::B>::B>::B> a1;
    >
    > giving an instance where "a template parameter can never be bound ... to
    > a class member."  The same would apply to an attempt to use a data
    > member for a non-template parameter:
    >
    >    template<int I>
    >    struct C
    >    {
    >       static const int i = 1;
    >    };
    >
    >    int main()
    >    {
    >       int i = C<C<C<...::i>::i>::i>::i;
    >    }
    >
    > or a member typedef:
    >
    >    template<typename T>
    >    struct D
    >    {
    >       typedef int type;
    >    };
    >
    >    int main()
    >    {
    >       D<D<D<...::type>::type>::type> d1;
    >    }
    >
    > Regards
    >
    > Paul Bibbings


    em... But it seems has little to do with the "trick" of instantiation
    point. I think (IMHO) Dr. BS is talking about something looks innocent
    but actually the compiler will reject.
    X, Jun 16, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    573
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    635
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    928
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    404
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    819
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page