typedef

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George3

    typedef


    Hello everyone,


    In the following segment, it does not compile because const is
    qualified on (the whole) type int& not on the near one int, right?


    Code:
    --------------------

    #include <iostream>

    using namespace std;

    typedef const int& rcInt;
    typedef int& int_ref_t;

    int main()
    {
    rcInt ref = 0; // compile ok

    const int_ref_t x = 0; // error C2440: 'initializing' : cannot convert from 'int' to 'int_ref_t'

    return 0;
    }

    --------------------



    thanks in advance,
    George



    --
    George3
    ------------------------------------------------------------------------
    Posted via http://www.codecomments.com
    ------------------------------------------------------------------------

  • Tamas Demjen

    #2
    Re: typedef

    George3 wrote:
    #include <iostream>
    >
    using namespace std;
    >
    typedef const int& rcInt;
    typedef int& int_ref_t;
    >
    int main()
    {
    rcInt ref = 0; // compile ok
    >
    const int_ref_t x = 0; // error C2440: 'initializing' : cannot convert from 'int' to 'int_ref_t'
    >
    return 0;
    }

    The type of `ref' is: int const &
    The type of `x' is: int & const

    This should point you to the right direction.

    Tom

    Comment

    • Tamas Demjen

      #3
      Re: typedef

      George,

      You posted this question to microsoft.publi c.vc.language, and it was
      already answered there. Do you realize that you are wasting people's time.

      Pick a group where your question belongs to. If you must post it to
      multiple groups, please crosspost. Had you crossposted this question,
      the previous answers would have showed up here.

      Multiposting causes the discussion to split between multiple groups.
      Only crossposting ensures that the full discussion gets combined.

      Tom

      Comment

      • David Wilkinson

        #4
        Re: typedef

        Tamas Demjen wrote:
        George,
        >
        You posted this question to microsoft.publi c.vc.language, and it was
        already answered there. Do you realize that you are wasting people's time.
        >
        Pick a group where your question belongs to. If you must post it to
        multiple groups, please crosspost. Had you crossposted this question,
        the previous answers would have showed up here.
        >
        Multiposting causes the discussion to split between multiple groups.
        Only crossposting ensures that the full discussion gets combined.
        Tamas:

        If you wish to change George's behavior (a good idea, IMHO), you need to post in
        microsoft.publi c.vc.language, because he only ever answers there.

        However I have become convinced that George is not s simple multi-poster. Either
        he is deliberately trying to disrupt these groups, or (as he claims) his posts
        are being copied to this group without his knowledge. Recent duplicated posts in
        this group are all "Posted via http://www.codecomment s.com", whereas the
        "original" posts in microsoft.publi c.vc.language are not.

        --
        David Wilkinson
        Visual C++ MVP

        Comment

        Working...