C++和Ruby之间有很多相似之处,其中一些是:
就像C++一样,在Ruby中…
Ruby和C++之间的区别。
Ruby | C++ |
---|---|
In Ruby, every variable is just an automatically dereferenced name for some object which means that there is no explicit references in Ruby. | Unlike Ruby there is explicit references in C++. |
Objects are strongly but dynamically typed in Ruby. | Objects are not strongly typed as that in Ruby. |
The “constructor” is called initialize instead of the class name. | This is not the case in C++. |
Array and Hash are only two container types. | There are many container types in C++. |
There’s no need of C++ templates. No casting either required. | C++ templates are necessary here. Casting is there. |
It’s self instead of this. | It is this instead of self. |
Iteration is done a bit differently. In Ruby, you don’t use a separate iterator object. Instead you use an iterator method of the container object that takes a block of code to which it passes successive elements. | Vectors are required and used in C++ which makes the coding easy. |
lib, a unit testing, comes standard with Ruby. | This is not available with C++. |
There’s no type conversions in Ruby. | Type conversion is necessary in C++. |
There are some enforced case-conventions. | No such case conventions are present in C++ which makes it easy. |
You can re-open a class anytime and also you can add more methods in Ruby. | We cannot do this in C++. |
Some methods end in a ’?’ or a ’!’ in Ruby. It’s actually part of the method name. | No such symbols are required at the end of methods in C++. |
All methods are always virtual in Ruby. | Methods are not virtual in C++. |
Multithreading is built-in, but as of Ruby 1.8 they are “green threads” as opposed to native threads. | Multithreading is not built-in in case of C++. |
Parentheses used for calling of method are usually optional in Ruby. | Parentheses are required in C++ and it is necessary. |
You don’t directly access member variables—all access to public member variables is via methods. | Member variables in C++ can be access directly. |
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。