Afew simple questions

G

Guest

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;
}
 
B

Bruno van Dooren

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(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;
}

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
(e-mail address removed)
Remove only "_nos_pam"
 
C

Carl Daniel [VC++ MVP]

Bruno said:
. is for selecting a member through an instance.
-> is for selecitng a member through a pointer

you meant :: here, not >>
^ 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
 
B

Bruno van Dooren

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.
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
(e-mail address removed)
Remove only "_nos_pam"
 
?

=?iso-8859-1?Q?Kim=20Gr=e4sman?=

Hi Carl and Bruno,
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?
 
B

Bruno van Dooren

is for selecting a scope / namespace
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
(e-mail address removed)
Remove only "_nos_pam"
 
H

Hendrik Schober

Carl Daniel said:
you meant :: here, not >>


You are using OE-QuoteFix said:
[...]
-cd

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

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

Carl Daniel [VC++ MVP]

Bruno said:
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
 
C

Carl Daniel [VC++ MVP]

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
 
H

Hendrik Schober

Carl Daniel said:
Hendrik said:
Carl Daniel [VC++ MVP]
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).

:blush:>

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top