Normally, the default constructor is always called. I'm not sure what exactly you're trying to accomplish other than that?
If you define another constructor, and not the default constructor, it will demand that you use that constructor.
Line 17 is the one that declares a2.
If you define another constructor, and not the default constructor, it will demand that you use that constructor.
$ cat test.cpp
#include <iostream>
#include <string>
class A
{
public:
A(int val) { val_ = val; }
int val_;
};
int main(int argc, char ** argv)
{
A a1(1);
std::cout << a1.val_ << std::endl;
A a2;
std::cout << a2.val_ << std::endl;
return 0;
}
$ g++ -Wall test.cpp
test.cpp: In function 'int main(int, char**)':
test.cpp:17: error: no matching function for call to 'A::A()'
test.cpp:8: note: candidates are: A::A(int)
test.cpp:6: note: A::A(const A&)
$
Line 17 is the one that declares a2.