A
Alexander Korovyev
Hello,
1) Should a standard compliant compiler accept the following code:
void Foo() { /* ... */ }
class Foo { /* ... */ };
int main()
{
Foo();
return 0;
}
If yes, what do you think the language allows it for? By the way, can
you predict what the program will do -- construct the object or call
the function?
2) Can you tell what exactly this short program will print?
#include<iostream>
using std::cout;
class MyClass {
public:
MyClass() : i_(2) {}
MyClass(const MyClass& obj) { i_ *= obj.i_; }
~MyClass() { cout << i_ << std::endl; }
private:
int i_;
};
int main()
{
MyClass( MyClass() );
return 0;
}
-Alexander
1) Should a standard compliant compiler accept the following code:
void Foo() { /* ... */ }
class Foo { /* ... */ };
int main()
{
Foo();
return 0;
}
If yes, what do you think the language allows it for? By the way, can
you predict what the program will do -- construct the object or call
the function?
2) Can you tell what exactly this short program will print?
#include<iostream>
using std::cout;
class MyClass {
public:
MyClass() : i_(2) {}
MyClass(const MyClass& obj) { i_ *= obj.i_; }
~MyClass() { cout << i_ << std::endl; }
private:
int i_;
};
int main()
{
MyClass( MyClass() );
return 0;
}
-Alexander