S
subramanian100in
Consider the following program named x.cpp:
#include <cstdlib>
using namespace std;
class Test
{
public:
Test();
};
Test::Test()
{
}
int main()
{
const Test x;
return EXIT_SUCCESS;
}
This program compiles fine with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
Now consider the following program y.cpp:
#include <cstdlib>
using namespace std;
class Test
{
};
int main()
{
const Test obj;
return EXIT_SUCCESS;
}
When I compile this program as
g++ -std=c++98 -pedantic -Wall -Wextra y.cpp
I get the following compilation error:
y.cpp: In function `int main()':
y.cpp:11: error: uninitialized const `obj'
y.cpp:11: warning: unused variable 'obj'
In x.cpp, the default ctor supplied by the class Test is used.
Why doesn't the compiler-supplied default ctor not used in y.cpp ?
Why do I get compilation error for y.cpp ?
Kindly explain.
Thanks
V.Subramanian
#include <cstdlib>
using namespace std;
class Test
{
public:
Test();
};
Test::Test()
{
}
int main()
{
const Test x;
return EXIT_SUCCESS;
}
This program compiles fine with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
Now consider the following program y.cpp:
#include <cstdlib>
using namespace std;
class Test
{
};
int main()
{
const Test obj;
return EXIT_SUCCESS;
}
When I compile this program as
g++ -std=c++98 -pedantic -Wall -Wextra y.cpp
I get the following compilation error:
y.cpp: In function `int main()':
y.cpp:11: error: uninitialized const `obj'
y.cpp:11: warning: unused variable 'obj'
In x.cpp, the default ctor supplied by the class Test is used.
Why doesn't the compiler-supplied default ctor not used in y.cpp ?
Why do I get compilation error for y.cpp ?
Kindly explain.
Thanks
V.Subramanian