RESONANCE - SOME BASIC RULES 1. Never change the locations of atoms in generating resonance structures. Only change the position of electrons, those in lone pairs or pi bonds.
a. When electrons of a pi bond are moved, they can only move into a sigma bond if that bond is to an unsaturated atom. Eg.
has no way to delocalize either the pi electrons or the lone pair of oxygen b. Lone pair electrons can only be delocalized to an unsaturated atom, one that has an electron deficiency to begin with possibly due to a positive charge, or one that is involved in a pi bond. The lone pair electrons of O can be delocalized in each of the structures below because O is bound to an unsaturated atom. If a lone pair atom is bonded to a saturated atom, there is no place to accommodate the lone pair electrons.
Structures which leave oxygen or other electronegative atoms without an octet are not significant contributors to the overall resonance hybrid.

This is reasonable and helpful in predicting the Never - very unreasonable to tendency of nucleophiles to attack a carbonyl move pi electrons away from carbon. the electronegative oxygen.
Both of these cations are especially stable because of the contributor which has octets for carbon and oxygen or nitrogen. A positive charge on a heteroatom is fine, if the heteroatom still has an octet of electrons.