visual c++ for .net(新语法)
生活随笔
收集整理的這篇文章主要介紹了
visual c++ for .net(新语法)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
一.Basic
二.Class
1.聲明一個引用類型(ref),即class
//========================================================================= // REF CLASSES //========================================================================= ref class R1 { public:R1() { X = 0; }int X;void F() {Console::WriteLine(" Value of X in instance of R1: {0}", X++);} }; void RefClasses() {R1^ r = gcnew R1;r->F();r->F(); }2.值類型用value class
//========================================================================= // VALUE CLASSES //========================================================================= value class V1 { public:int X;void F() {Console::WriteLine(" Value of X in instance of V1: {0}", X++);} }; void ValueClasses() {V1 v;v.F();v.F(); }3.聲明接口(interface class)
//========================================================================= // INTERFACES //========================================================================= interface class I1 {void F(); }; ref class R2 : I1 { public:R2() { X = 0; }int X;virtual void F() {Console::WriteLine(" Value of X in instance of R2 (I1): {0}", X++);} }; void Interfaces() {I1^ i = gcnew R2;i->F();i->F(); }4.抽象類(abstract 關鍵字放后面)
//========================================================================= // ABSTRACT //========================================================================= ref class Animal abstract { public:virtual String^ Habitat() {return "Earth";} }; ref class PolarBear : Animal { public:virtual String^ Habitat() override {return String::Concat("North Pole, ", Animal::Habitat());} }; void Abstract() {Animal^ creature = gcnew PolarBear;Console::WriteLine(" This animal is located at: {0}", creature->Habitat()); }5.密封類
// SEALED //========================================================================= ref class Currency { public:virtual String^ Color() {return "Every Color";} }; ref class Dollar sealed : Currency { public:virtual String^ Color() override {return "Green";} }; void Sealed() {Dollar^ buck = gcnew Dollar;Console::WriteLine(" The color of a dollar is: {0}",buck->Color()); }6.literal關鍵字
A variable (data member) marked as literal in a /clr compilation is the native equivalent of a static const variable.
ref struct X {literal int i = 4; }; int main() {int value = X::i; }7.無限循環
內部無限循環,這個記錄下
for(;;) {//... }轉載于:https://www.cnblogs.com/Clingingboy/archive/2011/04/12/2013328.html
總結
以上是生活随笔為你收集整理的visual c++ for .net(新语法)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: insert式注射攻击解析
- 下一篇: android利用WebView实现浏览