Class A
{
public:
A()
{
cout << "constructor called";
}
};
int main()
{
A obj; // constructor getting called
A obj1(); // constructor not getting called
}
当我实例化 obj 对象时,我的构造函数被调用。 但是当我实例化 obj1 时,我的构造函数没有被调用。
我想知道它的原因。
答案 0 :(得分:0)
()
实际上没有创建任何对象,它是一个函数声明。
A
,因为编译器无法判断您是创建obj1
对象还是声明A
函数返回 DatabaseReference myRef = FirebaseDatabase.getInstance().getReference().child("new");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
// Object key = dataSnapshot.getValue();
if (dataSnapshot.hasChild(ch) ) {
Map<String ,Object> key = (Map<String, Object>) dataSnapshot.child(ch).getValue();
sname = (String) key.get("sname");
// Log.v("ABCD ", "Value is: " + key.get("sname"));
if(dataSnapshot.getValue() != null)
{
Intent intent = new Intent("com.example.sunny.new.Selectclass");
startActivity(intent);
finish();
}
} else{
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
builder1.setMessage("Check your Code");
builder1.setCancelable(true);
builder1.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.v("XYZ", "Failed to read value.", error.toException());
}
});
个对象