Hi,
I was just browsing some java code and found that it is possible in java to call a constructor within another constructor. The rule being that the it should be first line in the constructor and also there shouldn't be any duplication.Bot h these rules have valid reasons. But why can't we do the same in c++.
Java Code :
public class c {
public c(){}
public c(int a){
this();
}
C++ code :
class c{
public :
c(){}
c(int a){
this->c(); >>> Error
}
};
I was just browsing some java code and found that it is possible in java to call a constructor within another constructor. The rule being that the it should be first line in the constructor and also there shouldn't be any duplication.Bot h these rules have valid reasons. But why can't we do the same in c++.
Java Code :
public class c {
public c(){}
public c(int a){
this();
}
C++ code :
class c{
public :
c(){}
c(int a){
this->c(); >>> Error
}
};
Comment