EDIT: This refers to C++ and not C++-cli which the post's tags now suggest the question is about.
C# is based on C++ in some ways, but a key feature of the language is that many of the complex issues C++ programmers have to deal with are handled for you by the run time< but the solutions are generic and so generally slower. It makes C# easier to learn and easier for a programmer to start achieving great results from, whereas a good C++ programmer has the ability to write much smaller, more efficient and more powerful applications.
In C++, references are indicated by placing an "&" after the type name in a variable declaration.
int i = 0;
int& j = i; // j is now an un-counted ref to i
These are not C#'s references though: they are not ref-counted, and cannot be re-assigned. Once you have aliased "j" to "i" in the above, you cannot change what it references.
int i = 0;
int& j = i;
int k = 2;
j = k; // translates to i = 2
You also have to be aware that, if the object of your reference goes away, you elicit undefined behavior:
int* i = new int(3); // "i" is actually a pointer, the address of the new integer.
int& j = *i; // j references the integer to which i points.
j = 2; // OK: translates to (*i) = 2;
delete i; // return it to the pool
j = 3; // UNDEFINED BEHAVIOR: translates to (*i) = 3 but we just released i.
There is also no "ref" keyword in C++, because there is no built-in ref counted type (you can, however, use std::shared_ptr/std::weak_ptr to achieve something similar).
"::" is the scope operator, used to indicate "belonging to the scope" whereas "." and "->" mean "members of an instance of" and "member of an instance pointed to by" respectively.
You'll use "::" when you want to access constant/static members of a class or members of a namespace, or when you need to disambiguate similar names that are in different namespaces.
class Foo {
public:
void herp();
enum { Bad = 0, Good = 1 };
static int open(); // could class with C-standard library 'open' function.
};
// Implement the member "herp" of Foo
void Foo::herp()
{
}
Since foo's "open()" function is declared static, it is not invoked by members but by Class.
// Using "::"
int quality = Foo::Good;
// Distinguish between 'open' in std vs foo
int fd = std::open("helloworld.txt");
int fd = Foo::open();
Lastly, you asked
What is difference between new type() and ref new type()
In C++ "new" means "allocate memory for and return a pointer to". This data is not ref-counted or managed in any way, it is your responsibility to ensure that the memory is freed otherwise you'll incur what is called a "memory leak". Consider:
#include <iostream>
class Foo {
char m_data[1024 * 1024 * 1024]; // 1Gb of data
public:
Foo() {
std::cout << "New Foo at " << (void*)this << std::endl;
}
~Foo() {
std::cout << "Releasing Foo at " << (void*)this << std::endl;
}
void doWork() {
// imagine the foo is doing some work
}
};
void makeFooDoWork() {
static const size_t FOOS_AT_A_TIME = 16;
Foo* f = new Foo[FOOS_AT_A_TIME];
for (size_t i = 0; i < FOOS_AT_A_TIME; ++i) {
foo[i]->doWork();
}
/* In C#:
These objects would call Destroy() as they went out of
scope making them available for garbage collection.
In C++:
allocated objects are YOUR responsibility. Nothing
happens to them automatically.
*/
// free [] f; // <-- what we ought to do here.
}
int main(int argc, char* argv[]) {
std::cout << "Creating first foo" << endl;
Foo* f1 = new Foo;
std::cout << "Releasing it" << endl;
delete f1;
for (size_t i = 0; i < 10000000; ++i) {
makeFooDoWork();
}
}
This program is likely to crash on most machines for the forseeable future because C++ does not have garbage collection so it is completely unaware that we are not tracking the objects we allocated.
Since it appears the question was actually about C++/CLI, let me add the following:
C++/CLI is a SECOND C++-derived language developed by Microsoft. You need to be careful in stipulating that you are asking questions about C++/CLI because it is NOT the same thing as C++, not by a long stretch. I cannot speak to the popularity of C++/CLI except that I don't know any C++/CLI programmers. I know Cobol programmers, C# developers, Objective-C guys out the wazoo, C programmers even ada and business basic programmers, I have a friend who's consultancy does nothing but LISP, I have dozens of friends who work for Microsoft and I have all kinds of microsoft-certified web/db/asp developers.
But nobody I know actually works with C++/CLI - I used it briefly to try and develop some .NET prototypes many years ago, but dropped it for C# the moment that was an option.
I would encourage you to choose either C++ or C#, and since you already know some C# that may be your best route (e.g. the Unity 3D engine lets you use C# for the scripting language); cross-platform development is possible with C# via Mono, C++/CLI is only, and barely, supported by Microsoft. C.f. There was no Intellisense for C++/CLI in VS2010, although it came back in 2012.