#include <iostream>
class SomeClass {
public:
SomeClass(): something(100) {
std::cout<<"constructing"<<std::endl;
}
~SomeClass() {
std::cout<<"destructing"<<std::endl;
}
void printSomething() {
std::cout<<something<<std::endl;
}
int something;
};
int main(int argc, char * argv[]) {
SomeClass(instSomeClass);
instSomeClass.printSomething();
return 0;
}
Whilst scrolling through some code the other day I came across something which I haven't seen before and don't fully understand. The example above, which compiles and runs, is similar and seems to declare and initialize an object using a notation which I didn't think was legal: SomeClass(instSomeClass);
I expected an 'instSomeClass undeclared' error or something similar.
Whats going on here? I assume the compiler is interpreting this as something like: SomeClass instSomeClass;
or SomeClass instSomeClass = SomeClass();
. I can't find any information on this online. Has anyone else seen this syntax that can explain? What is this called?