errors executing this code
|18|error: expected initializer before 'Myclass'|
|22|error: expected declaration before '}' token|
#include<iostream>
using namespace std;
class Myclass {
private:
int u=10;
int v=20;
int w=30;
int x=40;
int y=50;
public:
Myclass() : x(10), y(x + 10) {}
void print();
};
void Myclass::print()
{
cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y;
}
int add Myclass::display()
{
return x+y;
}
}
int main()
{
Myclass objone;
objone.print();
objone.display();
getchar();
return 0;
}
#include<iostream>
using namespace std;
class Myclass {
private:
int u=10;
int v=20;
int w=30;
int x=40;
int y=50;
public:
Myclass() : x(10), y(x + 10) {}
void print();
void display();
};
void Myclass::print()
{
cout<<"u = "<<u<<" v = "<<v<<"w = "<<w<<" x = "<<x<<" y = "<<y;
}
void Myclass::display()
{
cout << "\nx + y = " << x + y;
}
int main()
{
Myclass objone;
objone.print();
objone.display();
getchar();
return 0;
}
Comments
Leave a comment