I am learning C++. Now I don't fully understand what this does
Some_Class::Some_Class {
etc...
}
I would do some research for myself, but I'm not sure where to begin or what's it called. Help would be appreciated.
I am learning C++. Now I don't fully understand what this does
Some_Class::Some_Class {
etc...
}
I would do some research for myself, but I'm not sure where to begin or what's it called. Help would be appreciated.
There's no way to say what it is, since the "code" you posted is invalid and ambiguous.
It could be a nested class definition made in out-of-class fashion. When you define nested classes, you can immediately define the inner class inside, as in
class Some_Class { // <- definition of the outer class
...
class SomeClass { // <- definition of the inner class
...
};
...
};
Or, if you prefer, you can only declare the nested class inside, and move the actual definition outside
class Some_Class { // <- definition of the outer class
...
class SomeClass; // <- declaration of the inner class
...
};
class Some_Class::SomeClass { // <- definition of the inner class
...
};
However, for that it has to begin with class/struct
, which is not present in what you posted.
Or it could be a definition of member function SomeClass
of class Some_Class
.
class Some_Class {
...
void SomeClass(int i); // <- declaration of member function
...
};
void Some_Class::SomeClass(int i) // <- definition of member function
{
...
}
But for that it has to include return type and parameter list.
Or it could be a definition of a static member with {}
-enclosed initializer
class Some_Class {
...
static int SomeClass;
...
};
int Some_Class::SomeClass { 42 };
But for that it has to include static member's type.
In other words, there's no way to say what it is you posted and what your question is really about.
The :: resolves either a class or namespace.
For example
namespace test1 { int i = 0; }
cout << test1::i << endl;
or
class test2 {
public:
static int i = 0;
};
// after in
cout << test2::i << endl;
You can also add this:
using namespace test1;
cout << i << endl;
You are confused by the scope resolution operator (thanks @Huytard for the link)
:: is the scope resolution operator - it means, that SomeClass
method is in Some_Class
, given your example -Some_Class::SomeClass