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;
}

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]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.