CLI/C++. How does it differ to 'normal' c++ or visual c#?

三世轮回 提交于 2019-12-12 02:50:07

问题


I was programming some not ambitious, small programs in my school in Dev C++ for ages now in school. But now it came out i need to make a window application. I saw some people using visual studio for that.

Few days ago i got Visual Studio C++ express, and i after a while of coding, after few lines i realized it differs much from "normal" C++ i was using so far. Even declarations of strings are giving me headache. I wanted to ask, if maybe visual c# would be more similar to what i know, or maybe there is some other way for me, to code window application in C++ i know, using drag and drop interface, when it comes to creating buttons, textboxes and stuff (like in visual studio)?

So most importantly, is Visual c# more like "normal" c++, and if not, do you guys got any suggestions to replace Visual? any help appreciated.


回答1:


C++ and C++/CLI, are really just different languages, designed for different purposes. C++/CLI is designed with one target in mind -- the CLR, and thus exposes garbage collected pointers, interfaces, delegates, and similar as first class components of the language. C++/CLI is designed such that most code which is valid C++ can be compiled to target the CLR without being rewritten, however. The downside here is that compiling existing C++ code will typically use native pointers, which cannot be expressed on the CLR unless it is put into unsafe mode. This means you can not run such compiled code in partial trust environments, such as Sliverlight or Windows Phone.

C++, on the other hand, is a general purpose programming language designed to target all computer systems, from the largest mainframe to the smallest microcontroller. There are not features like garbage collected pointers or delegates available because providing such features would be extremely difficult on some types of hardware.

Really, despite sharing similar syntax, they are two completely separate languages. C++/CLI is usually written in a style closer to C# than to C++.

Now, to address your specific concerns:

Even declarations of strings are giving me headache.

C++/CLI provides a System::String type as part of it's base class library. Standard C++ also provides std::basic_string (which is typedef'd to std::string when specialized for char) Therefore, you might see some kinds of conflicts, and the only way to deal with this is usually to specify the one you want explicitly.

I wanted to ask, if maybe visual c# would be more similar to what i know, or maybe there is some other way for me, to code window application in C++ i know, using drag and drop interface, when it comes to creating buttons, textboxes and stuff (like in visual studio)?

EDIT : The following may no longer be true in Visual Studio 2010. I've not had a chance to verify. (See comments on this answer for more details)

There is no visual designer kind of tool available in Visual Studio to produce C++ applications. There are designers for WPF and Windows Forms, both of which are CLR technologies. To use these designers you must use C++/CLI, rather than C++.



来源:https://stackoverflow.com/questions/8275517/cli-c-how-does-it-differ-to-normal-c-or-visual-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!