What happens if a class does not have a name?

Phạm Quyết

New member
What happens if a class does not have a name?
A. It will not have a constructor
B. It will not have a destructor
C. It is not allowed
D. It will neither have a constructor or destructor
 
Answer: b
Explanation: A class without a name will not have a destructor. The object is made so constructor is required but the destructor is not. Check the code below:
Code:
#include <iostream>
using namespace std;
class
{
    public:
	void func()
        {
		cout<<"Hello world";
	}
}a;
int main(int argc, char const *argv[])
{
	a.func();
	return 0;
}
 

Tìm kiếm

Back
Top