有一些简单的问题 [英] Afew simple questions

查看:87
本文介绍了有一些简单的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



尝试学习c ++并且对于一些事情我正在挣扎

1)之间的差异是什么?和-and ::?

2)为什么你在声明一个物体后有时必须使用^,它是什么特别好?

它做了什么?

3)&之间的差异是什么?和*? (我知道*是指针)

4)托管和非托管代码,差异是什么?

我正在尝试编写一个简单的类:

当我编译时我得到以下错误:

错误1错误C3265:无法在非托管中声明托管''mId''

''PatryManager ::派对''

错误2错误C3265:无法在非托管中声明托管''mName''
''PatryManager :: Party''


类派对

{

公开:

派对();

派对(String ^ id);

无效NewId();

~派对();


私人:

String ^ mId;

String ^ mName;

};


Party :: Party()

{

}

Party :: Party(String ^ id)

{

mId = id;

}

派对::〜派对()

{

//销毁物品
}


无效Party :: NewId()

{

Rando m ^ mRandGenerator;

int tempId = 0;


String ^ mTemp = String :: Empty;

char mLetterA [1 ];

char mLetterB [1];


tempId = mRandGenerator->下一步(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;

}

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

推荐答案

尝试学习c ++并且我正在为一些事情挣扎
Trying to learn c++ and am woundering over afew things

1)之间的差异是什么? 。和 - 和::?
1) What is the diffrence between . and -and :: ?



..用于通过实例选择成员。

-is用于通过指针选择成员

::用于选择范围/命名空间

.. is for selecting a member through an instance.
-is for selecitng a member through a pointer
:: is for selecting a scope / namespace


2)为什么有时你必须在声明一个对象后使用^,

exacly

它做到了吗?
2) Why do you sometimes have to use ^ after declaring a object, what
exacly
does it do?



^表示托管引用。这是你在使用

..NET类时使用的东西。

^ indicates a managed reference. this is something you use when working with
..NET classes.


3)&之间的差异是什么?和*? (我知道*是一个指针)
3) What is the diffrence between & and *? (I know that * is a pointer)



&返回实例的地址(引用)。 *取消引用指针。

& returns the address (reference) of an instance. * dereferences a pointer.


4)托管和非托管代码,是什么?
4) Managed and Unmanaged code, whats the diffrence?



托管代码使用公共语言运行库。你在使用目标.NET框架的时候使用托管代码。

unmanaged是你编译为本机代码的时候。

managed code uses the common language runtime. you use managed code when
targetting the .NET framework.
unmanaged is when you compile to native code.


我正在尝试写一个简单的类:

当我编译时我得到以下错误:

错误1错误C3265:无法声明托管''mId''在一个非托管的

''PatryManager :: Party''

错误2错误C3265:无法在非托管中声明托管''mName''

''PatryManager ::派对'


级派对

{

public:

Party();

Party(String ^ id);

void NewId();

~Party();


私人:

String ^ mId;

String ^ mName;

};


派对::派对()

{

}

派对::派对(String ^ id)

{

mId = id;

}

派对::〜派对()

{

//销毁物品

}


void Party :: NewId()

{

Random ^ mRandGenerator;

int tempId = 0;


String ^ mTemp = String :: Empty;

char mLetterA [1];

char mLetterB [1 ];


tempId = mRandGenerator->下一步(1000,9999);

mLetterA [0] =(char)mRandGenerator->下一步(1 ,25);

mLetterB [0] =(char)mRandGenerator->下一步(1,25);


mTemp = tempId.ToString() + mLetterA [0] + mLetterB [0];

mId = mTemp;

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



你是混合托管和非托管C ++。这不是不可能的,但是

是你必须遵循的一些规则。


我建议你先学习C ++,然后才开始管理代码和混合代码

当你完全理解基础知识时。

否则你会遇到问题。

有几个好的关于学习C ++主题的书籍。

我最喜欢的仍然是'c ++编程语言,3d版''by bjarne

stroustrub。


-


亲切的问候,

Bruno van Dooren
BR ********************** @ hotmail.com

仅删除_nos_pam

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
br**********************@hotmail.com
Remove only "_nos_pam"


Bruno van Dooren写道:
Bruno van Dooren wrote:

>尝试学习c ++并且对于一些事情我正在挣扎
1)两者之间的差异是什么。和 - 和::?
>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)为什么有时你必须在声明一个对象后使用^,它有什么作用呢?
>2) Why do you sometimes have to use ^ after declaring a object, what
exacly
does it do?



^表示托管引用。这是使用.NET类时使用的


^ indicates a managed reference. this is something you use when
working with .NET classes.



实际上,^是一个托管指针(或句柄),而%是一个托管的

参考。

-cd

Actually, ^ is a managed pointer (or handle), while % is a managed
reference.

-cd


>>>用于选择范围/命名空间
>>>is for selecting a scope / namespace

>

你的意思是::这里,不是>>
>
you meant :: here, not >>



拼写错误。我的笔记本键盘有azerty布局。我已将其配置为qwerty

(就像每个理智的C ++ / C#程序员一样)但我不时会输入错误。

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)为什么在声明一个对象之后你有时必须使用^,它有什么用呢?
>>2) Why do you sometimes have to use ^ after declaring a object, what
exacly
does it do?


^表示托管引用。这是在使用.NET类时使用的。


^ 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.



哎呀。我似乎混淆了2种语言的术语。

在C#中,术语引用用于C ++使用管理指针的地方。


-


亲切的问候,

Bruno van Dooren
BR ********************** @ hotmail.com

仅删除_nos_pam

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
br**********************@hotmail.com
Remove only "_nos_pam"


这篇关于有一些简单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆