0

hi i have this question..i solved it but im not sure if its true or not..

template<class t>
class c
{

private:

int size;
t *p;

public:

void set(int sv)
{
if(p!=0)

{delete[] p;}

p=new t[sv];

for (int i=0;i<sv;i++)

cin>>p[i];

}

c()
{
size=0;
p=0;
}

the question is that I have to add print function &
overloading for (operator ==, operator =, operator++(pre and post))

here are my answers..plzzz check them for me.

void c:: print()
{
cout<<"x= "<<x;
cout<<"p= "<<&p;
}

bool c:: operator ==(c &o) //return true if same size&elements

{
    return(size==o.size)
}


void c:: operator =(c &o)    //deep copy
{
    if(p1!=0)
        delete p1;

    p1=new int;
    *p1=*(o.p1);
}


c c:: operator ++(int )    // add to every element in array +1
{
    c result;
    result=*this;
    x++;
    y++;
    return result;
}

c c:: operator ++()        // add to every element in array +1
{
    ++x;
    ++y;
    return *this;
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jonsca
0

here are my answers..plzzz check them for me.

Here's a wild idea. What happens when you run them in your program? Do they work there?

And "plzzz" use code tags:

[code]

//code goes here

[/code]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.