Afew simple questions

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

    #1

    Afew simple questions

    Hi
    Trying to learn c++ and am woundering over afew things
    1) What is the diffrence between . and -and :: ?
    2) Why do you sometimes have to use ^ after declaring a object, what exacly
    does it do?
    3) What is the diffrence between & and *? (I know that * is a pointer)
    4) Managed and Unmanaged code, whats the diffrence?
    I am trying to write a simple class:
    when i compile i get the following error:
    Error 1 error C3265: cannot declare a managed 'mId' in an unmanaged
    'PatryManager:: Party'
    Error 2 error C3265: cannot declare a managed 'mName' in an unmanaged
    'PatryManager:: Party'

    class Party
    {
    public:
    Party();
    Party(String^ id);
    void NewId();
    ~Party();

    private:
    String^ mId;
    String^ mName;
    };

    Party::Party()
    {
    }
    Party::Party(St ring^ id)
    {
    mId = id;
    }
    Party::~Party()
    {
    // Destroy objects
    }

    void Party::NewId()
    {
    Random^ mRandGenerator;
    int tempId = 0;

    String^ mTemp = String::Empty;
    char mLetterA[1];
    char mLetterB[1];

    tempId = mRandGenerator->Next(1000,9999 );
    mLetterA[0] = (char)mRandGene rator->Next(1,25);
    mLetterB[0] = (char)mRandGene rator->Next(1,25);

    mTemp = tempId.ToString () + mLetterA[0] + mLetterB[0];
    mId = mTemp;
    }
  • Bruno van Dooren

    #2
    Re: Afew simple questions

    Trying to learn c++ and am woundering over afew things
    1) What is the diffrence between . and -and :: ?
    .. is for selecting a member through an instance.
    -is for selecitng a member through a pointer
    :: is for selecting a scope / namespace
    2) Why do you sometimes have to use ^ after declaring a object, what
    exacly
    does it do?
    ^ indicates a managed reference. this is something you use when working with
    ..NET classes.
    3) What is the diffrence between & and *? (I know that * is a pointer)
    & returns the address (reference) of an instance. * dereferences a pointer.
    4) Managed and Unmanaged code, whats the diffrence?
    managed code uses the common language runtime. you use managed code when
    targetting the .NET framework.
    unmanaged is when you compile to native code.
    I am trying to write a simple class:
    when i compile i get the following error:
    Error 1 error C3265: cannot declare a managed 'mId' in an unmanaged
    'PatryManager:: Party'
    Error 2 error C3265: cannot declare a managed 'mName' in an unmanaged
    'PatryManager:: Party'
    >
    class Party
    {
    public:
    Party();
    Party(String^ id);
    void NewId();
    ~Party();
    >
    private:
    String^ mId;
    String^ mName;
    };
    >
    Party::Party()
    {
    }
    Party::Party(St ring^ id)
    {
    mId = id;
    }
    Party::~Party()
    {
    // Destroy objects
    }
    >
    void Party::NewId()
    {
    Random^ mRandGenerator;
    int tempId = 0;
    >
    String^ mTemp = String::Empty;
    char mLetterA[1];
    char mLetterB[1];
    >
    tempId = mRandGenerator->Next(1000,9999 );
    mLetterA[0] = (char)mRandGene rator->Next(1,25);
    mLetterB[0] = (char)mRandGene rator->Next(1,25);
    >
    mTemp = tempId.ToString () + mLetterA[0] + mLetterB[0];
    mId = mTemp;
    }
    you are mixing managed and unmanaged C++. this is not impossible, but there
    are a number of rules that you have to follow.

    I suggest you learn C++ first, and only start on managed code and mixed code
    when you fully understand the basics.
    otherwise you will run into problems with everything you do.
    there are several good books on the topic of learning C++.
    my favorite is still 'the C++ programming language, 3d edition' by bjarne
    stroustrub.

    --

    Kind regards,
    Bruno van Dooren
    bruno_nos_pam_v an_dooren@hotma il.com
    Remove only "_nos_pam"


    Comment

    • Carl Daniel [VC++ MVP]

      #3
      Re: Afew simple questions

      Bruno van Dooren wrote:
      >Trying to learn c++ and am woundering over afew things
      >1) What is the diffrence between . and -and :: ?
      . is for selecting a member through an instance.
      -is for selecitng a member through a pointer
      >>is for selecting a scope / namespace
      you meant :: here, not >>
      >
      >2) Why do you sometimes have to use ^ after declaring a object, what
      >exacly
      >does it do?
      >
      ^ indicates a managed reference. this is something you use when
      working with .NET classes.
      Actually, ^ is a managed pointer (or handle), while % is a managed
      reference.

      -cd


      Comment

      • Bruno van Dooren

        #4
        Re: Afew simple questions

        >>>is for selecting a scope / namespace
        >
        you meant :: here, not >>
        typo. my laptop keyboard has azerty layout. I have configured it as qwerty
        (like every sane C++/C# programmer) but from time to time I mistype.
        >>2) Why do you sometimes have to use ^ after declaring a object, what
        >>exacly
        >>does it do?
        >>
        >^ indicates a managed reference. this is something you use when
        >working with .NET classes.
        >
        Actually, ^ is a managed pointer (or handle), while % is a managed
        reference.
        Oops. It seems I confused terminology of 2 languages.
        In C# the term 'reference' is used where C++ uses 'managed pointer'.

        --

        Kind regards,
        Bruno van Dooren
        bruno_nos_pam_v an_dooren@hotma il.com
        Remove only "_nos_pam"


        Comment

        • Kim Gräsman

          #5
          Re: Afew simple questions

          Hi Carl and Bruno,
          >>>is for selecting a scope / namespace
          >
          you meant :: here, not >>
          Strange. In my reader, Bruno's response said:

          ":: is for selecting a scope / namespace"

          Are you sure your newsreader doesn't interpret :: as a quote-prefix, Carl?

          --
          Best regards,
          Kim Gräsman


          Comment

          • Bruno van Dooren

            #6
            Re: Afew simple questions

            >>>>is for selecting a scope / namespace
            >>
            >you meant :: here, not >>
            >
            Strange. In my reader, Bruno's response said:
            >
            ":: is for selecting a scope / namespace"
            >
            Are you sure your newsreader doesn't interpret :: as a quote-prefix, Carl?
            I just went back to read it, and it says :: indeed.
            Since the : is just above the on my imaginary qwerty keyboard, I figured I
            mistyped.
            I'm using OE btw.

            I do know that '--' (without the quotes) indicates the beginning of a
            signature in some news readers.

            --

            Kind regards,
            Bruno van Dooren
            bruno_nos_pam_v an_dooren@hotma il.com
            Remove only "_nos_pam"


            Comment

            • Hendrik Schober

              #7
              Re: Afew simple questions

              Carl Daniel [VC++ MVP] <cpdaniel_remov e_this_and_nosp am@mvps.org.nos pamwrote:
              Bruno van Dooren wrote:
              Trying to learn c++ and am woundering over afew things
              1) What is the diffrence between . and -and :: ?
              . is for selecting a member through an instance.
              -is for selecitng a member through a pointer
              :: is for selecting a scope / namespace
              >
              you meant :: here, not >>

              You are using OE-QuoteFix, then? <g>
              [...]
              -cd
              Schobi

              --
              SpamTrap@gmx.de is never read
              I'm Schobi at suespammers dot org

              "The sarcasm is mightier than the sword."
              Eric Jarvis


              Comment

              • Carl Daniel [VC++ MVP]

                #8
                Re: Afew simple questions

                Bruno van Dooren wrote:
                >Actually, ^ is a managed pointer (or handle), while % is a managed
                >reference.
                >
                Oops. It seems I confused terminology of 2 languages.
                In C# the term 'reference' is used where C++ uses 'managed pointer'.
                Nice how they keep it consistent, eh?

                -cd


                Comment

                • Carl Daniel [VC++ MVP]

                  #9
                  Re: Afew simple questions

                  Bruno van Dooren wrote:
                  >>>>>is for selecting a scope / namespace
                  >>>
                  >>you meant :: here, not >>
                  >>
                  >Strange. In my reader, Bruno's response said:
                  >>
                  > ":: is for selecting a scope / namespace"
                  >>
                  >Are you sure your newsreader doesn't interpret :: as a quote-prefix,
                  >Carl?
                  Wierd. May OEQuoteFix is "fixing" it for me. I don't think OE by itself
                  would do that, but I've been running with OEQuoteFix for so long, I forget
                  that it's there.

                  -cd


                  Comment

                  • Carl Daniel [VC++ MVP]

                    #10
                    Re: Afew simple questions

                    Hendrik Schober wrote:
                    Carl Daniel [VC++ MVP]
                    <cpdaniel_remov e_this_and_nosp am@mvps.org.nos pamwrote:
                    >Bruno van Dooren wrote:
                    >>>Trying to learn c++ and am woundering over afew things
                    >>>1) What is the diffrence between . and -and :: ?
                    >>. is for selecting a member through an instance.
                    >>-is for selecitng a member through a pointer
                    >>>>is for selecting a scope / namespace
                    >>
                    >you meant :: here, not >>
                    >
                    >
                    You are using OE-QuoteFix, then? <g>
                    Yep.

                    -cd


                    Comment

                    • Hendrik Schober

                      #11
                      Re: Afew simple questions

                      Carl Daniel [VC++ MVP] <cpdaniel_remov e_this_and_nosp am@mvps.org.nos pamwrote:
                      Hendrik Schober wrote:
                      Carl Daniel [VC++ MVP]
                      <cpdaniel_remov e_this_and_nosp am@mvps.org.nos pamwrote:
                      Bruno van Dooren wrote:
                      Trying to learn c++ and am woundering over afew things
                      1) What is the diffrence between . and -and :: ?
                      . is for selecting a member through an instance.
                      -is for selecitng a member through a pointer
                      is for selecting a scope / namespace
                      >
                      you meant :: here, not >>

                      You are using OE-QuoteFix, then? <g>
                      >
                      Yep.
                      Press the Alt key and click on a mail/posting then
                      (see under Advanced Options).

                      :o>
                      -cd
                      Schobi

                      --
                      SpamTrap@gmx.de is never read
                      I'm Schobi at suespammers dot org

                      "The sarcasm is mightier than the sword."
                      Eric Jarvis


                      Comment

                      Working...