#include<iostream.h>
class Exforsys();

{
    private:
        int a;
    public:
        Exforsys()
        {}
        Exforsys(int w)
    {
        a=w;
    }
    Exforsys(Exforsys& e)
    {
        a=e.a;
        cout<<"Example of Copy Constructor";
    }
    void result()
    {
        cout<<a;
    }

    void main()
    {
    Exforsys e1(50);
    Exforsys e3(e1); cout<<"\ne3="; e3.result();
    } 
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

3 problems

Declaration of a copy constructor should be of a const reference variable parameter and not just a reference variable parameter--

Exforsys(const Exforsys& e)

--you might get away with it during compile/run but your professor may dock you points.

second, not sure if void main() is going to work on all c++ compilers, use int main and return 0.

finally, I'm pretty sure you have to type "using namespace std;" to use cout... not to mention the missing endl or flush statement after pushing a string into the stream.

You need to have a global main too.

::main();

And please use code tags around your code, it helps those who wants to help you :)

Edited 6 Years Ago by vidit_X: n/a

I dont think all above changes are needed.

This will work

#include<iostream.h>
using namespace std;           
class Exforsys
{
private:
   int a;
public:
   Exforsys()
   {}
   Exforsys(int w)
   {
   a=w;
   }
   Exforsys(Exforsys& e)
   {
   a=e.a;
   cout<<"Example of Copy Constructor";
   }
    void result()
   {
   cout<<a;
   }
};

int main()
{
Exforsys e1(50);
Exforsys e3(e1);
cout<<"\ne3="<<e3.result();
return 0;
}

Edited 6 Years Ago by stevanity: n/a

i tried the above code posted by stevanity but there is error which is:

error C2143: syntax error : missing ';' before '<<'

but when i place ";" before '<<', there is still an error...

This article has been dead for over six months. Start a new discussion instead.