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 2 of 3.
Rahul said:
1 decade ago
#include<iostream.h>
class { public : int x; }a; //a is the object of this class
int main(){
a.x=10;
cout<<"a="<<a.x;
return 0;
}
Execute the above code one can get to know about class without name.
class { public : int x; }a; //a is the object of this class
int main(){
a.x=10;
cout<<"a="<<a.x;
return 0;
}
Execute the above code one can get to know about class without name.
Naveen pateriya vidisha said:
1 decade ago
Nice discussion its possible blindly to create a name less class.
Tejas said:
1 decade ago
But my compiler reports an error.
Chintan said:
10 years ago
If you create class but not having any name, gives compilation error. So I think answer C is right.
Jatin said:
10 years ago
@Rahul.
I'm not getting any output as per your code.
I'm not getting any output as per your code.
Monika said:
9 years ago
Not satisfied with the answer of this question please elaborate.
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
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) ;
}
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.
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;
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers