Can functions....

...be nested inside other functions

Answer this question

Can functions....

  • Josh D

    No this is not possible - though you can define a local type which can have member functions.

    void f()
    {
    int i = 4;

    class X {
    public:
    X(int& i) : m_i(i) { }

    void Incr(int v) {
    m_i += v;
    }

    private:
    int& m_i;
    } x(i);

    x.Incr(4);
    }



  • vikionline

    I once downloaded the "C++/CLI Standard" draft by MS. Is VC2005's complier built based on this standard (with some MS extensions to C++ standard, I'm mainly interested in the C++ part of that standard) For example, in that draft, it explicitly states the new parsing syntax of >> in template declaration which is first introduced in VS2005.
  • DiegoCrespo

    With Visual C++ 2005 there is also for each that can be applied to iterators - the C++ Committee may also add this feature but it looks like they may use a slightly different syntax. I think that we may also support explicitly sized enums in native code - again this is something that the Committee is looking at adding to the next revision of the C++ Standard.

  • Gabe Covert

    Thanks for the reply, is there any lists of such extensions made by MS

    I'd like to make my code not rely too much on the MS extensions. For eg, I find enum can be forward declared in VC which is not allowed in standard.


  • ewillie

    Yes: the compiler is pretty much based on both the ECMA Standard for C++/CLI (ECMA-372) and the ISO/IEC Standard for C++ (ISO/IEC 14882:2003). The ECMA Standard can be downloaded from:

    http://www.ecma-international.org/publications/standards/Ecma-372.htm



  • PalMan

    The lifting of this restriction is currently under discussion by the C++ Standards committee: as we had so many requests for this feature we thought we'd go ahead and get some early implementation experience.

  • fuul

    I have a related question.

    In the c++ standard, it is said that "A type without linkage (3.5) shall not be used as a template-argument for a template type-parameter.

    [ Example:

    template < class T > class X { /*...*/ };

    void f() {

    struct S { /*...*/ };

    X<S > x3 ; // error: local type used as template-argument

    X<S*> x4 ; // error: pointer to local type used as template-argument

    }

    —end example ] [ Note: a template type argument may be an incomplete type (
    3.9). —end note ]"

    But it's allowed in VC complier. Is that the intended behavior


  • Can functions....