C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 47)
47.
What will happen if a class is not having any name?
Discussion:
25 comments Page 1 of 3.
Salvin kajar said:
7 years ago
As per my knowledge, if a class is not having a name then it's an anonymous class and anonymous class can not have a constructor but it can have a destructor.
(2)
Navya said:
5 years ago
It can have a destructor for the deallocation of memory, but the constructor cannot be allocated.
(1)
Tejas said:
1 decade ago
But my compiler reports an error.
Harsh said:
6 years ago
If the constructor is not made by the user then the complier automatically makes default constructor. Answer is. It connot has destructor.
Sravani Gudimetla said:
6 years ago
@Jathin:
In Rahul's code , instead of "#include<iostream.h>" you add "#include<iostream>"
Then you won't get any error.
In Rahul's code , instead of "#include<iostream.h>" you add "#include<iostream>"
Then you won't get any error.
Nikhil said:
7 years ago
Can I do this for java too?
How can I do it for the class which contains main function.
How can I do it for the class which contains main function.
Ramanand said:
7 years ago
@All.
As per my knowledge.
#include<iostream>
using namespace std;
class
{
public:
void aa()
{
cout<<"aryan"<<endl;
}
}a;
int main()
{
a.aa();
return 0;
}
As per my knowledge.
#include<iostream>
using namespace std;
class
{
public:
void aa()
{
cout<<"aryan"<<endl;
}
}a;
int main()
{
a.aa();
return 0;
}
Neha said:
8 years ago
Use this code.
#include <iostream>
using namespace std;
class
{
public :
int x;
}a; //a is the object of this class.
int main ()
{
a.x=10;
cout<<a.x;
return (0) ;
}
This code provides warning but gives output.
#include <iostream>
using namespace std;
class
{
public :
int x;
}a; //a is the object of this class.
int main ()
{
a.x=10;
cout<<a.x;
return (0) ;
}
This code provides warning but gives output.
Abhishek Chouhan said:
9 years ago
@Aarti
Your code is quite wrong, are you trying to access x data member of the nameless class?
Use this code.
#include <iostream>
using namespace std;
class
{
public :
int x;
}a; //a is the object of this class.
int main ()
{
a.x=10;
cout<<a.x;
return (0) ;
}
Your code is quite wrong, are you trying to access x data member of the nameless class?
Use this code.
#include <iostream>
using namespace std;
class
{
public :
int x;
}a; //a is the object of this class.
int main ()
{
a.x=10;
cout<<a.x;
return (0) ;
}
Aarti said:
9 years ago
As said above, I have written the below code,
#include
Class
{
public :
int x;
}a; //a is the object of this class.
int main ()
{
A. X=10;.
Cout<<"a="<
Return (0) ;
}
It is giving me warning in the same compiler given here "Online C++ Compiler",
"Line 3: warning: non-local variable a' uses anonymous type".
#include
Class
{
public :
int x;
}a; //a is the object of this class.
int main ()
{
A. X=10;.
Cout<<"a="<
Return (0) ;
}
It is giving me warning in the same compiler given here "Online C++ Compiler",
"Line 3: warning: non-local variable
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers