Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2006

Tip: Looking for answers? Try searching our database.

Afew simple questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick F - 10 Jul 2006 15:46 GMT
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(String^ 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)mRandGenerator->Next(1,25);
    mLetterB[0] = (char)mRandGenerator->Next(1,25);

    mTemp = tempId.ToString() + mLetterA[0] + mLetterB[0];
    mId = mTemp;
    }
Bruno van Dooren - 10 Jul 2006 16:14 GMT
> 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:
[quoted text clipped - 44 lines]
> 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.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Carl Daniel [VC++ MVP] - 11 Jul 2006 06:19 GMT
>> 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
Bruno van Dooren - 11 Jul 2006 07:30 GMT
>>>> 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
[quoted text clipped - 5 lines]
> 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'.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Carl Daniel [VC++ MVP] - 11 Jul 2006 16:44 GMT
>> 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
Kim Gräsman - 11 Jul 2006 08:28 GMT
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
Bruno van Dooren - 11 Jul 2006 09:05 GMT
>>>>> is for selecting a scope / namespace
>>
[quoted text clipped - 5 lines]
>
> 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.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Carl Daniel [VC++ MVP] - 11 Jul 2006 16:46 GMT
>>>>>> is for selecting a scope / namespace
>>>
[quoted text clipped - 6 lines]
>> 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
Hendrik Schober - 11 Jul 2006 15:28 GMT
> > > Trying to learn c++ and am woundering over afew things
> > > 1) What is the diffrence between . and -> and :: ?
[quoted text clipped - 3 lines]
>
> you meant :: here, not >>

 You are using OE-QuoteFix, then? <g>

> [...]
> -cd

 Schobi

Signature

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

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

Carl Daniel [VC++ MVP] - 11 Jul 2006 16:46 GMT
> Carl Daniel [VC++ MVP]
> <cpdaniel_remove_this_and_nospam@mvps.org.nospam> wrote:
[quoted text clipped - 7 lines]
>
>  You are using OE-QuoteFix, then? <g>

Yep.

-cd
Hendrik Schober - 17 Jul 2006 10:25 GMT
> > Carl Daniel [VC++ MVP]
> > <cpdaniel_remove_this_and_nospam@mvps.org.nospam> wrote:
[quoted text clipped - 9 lines]
>
> Yep.

 Press the Alt key and click on a mail/posting then
 (see under Advanced Options).

 :o>

> -cd

 Schobi

Signature

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

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.