Question: I know it is a fairly basic violation, but what is it?

```
class xyz
{
    void function1()
    {
        cout<<"in class";
    }
};

int main()
{
    xyz s1 = new xyz(100);
    xyz s2 = s1;
    s2.function1();
    delete s1;
    return 0;
}

```

Something is wrong about the memory allocation using `new`. I believe but I can't seem to understand the fundamental behind it and the resolution.

Answer: 
`new` returns a pointer (`xyz *`) to an object, not an object, so you should correct the type of `s1`:

```
xyz* s1=new xyz(100);

```

and to call the method through the pointer you should use operator `->`:

```
s1->function1();

```

which is the equivalent of dereferencing the pointer and calling the method on the object:

```
(*s1).function1();

```
You can't assign `T*` to `T` (pathological cases aside).

```
xyz * s1 = new xyz();
xyz * s2 = s1;
s2->function1();
delete s1;
return 0;

```

Better yet, don't use naked `new` and `delete` and use a smart pointer:

```
auto s1 = make_unique<xyz>();
xyz * s2 = s1.get(); // non-owning pointer
s2->function1();
// no explicit delete necessary

```