You mean, like the Yamato? It doesn't work
.
The Japanese battleship Yamato had special anti-aircraft shells for its biggest guns. This was the only example I know where a historical capship attempted to use its main weaponry against aircraft. The significant fact about this attempt is that
it just plain didn't work. It only got to fire them once as the aircraft approached, and beyond that, it couldn't bring those huge guns to bear again, so it was back to ordinary small anti-aircraft guns.
Even today, if an aircraft were to get close to a modern warship, it would come down to missile launchers and paltry little gun turrets. It's a matter of maneouvrability and refire rate - we know those bug capships have huge and powerful weapons for use against big capships, but we can imagine it's pretty much impossible to bring them to bear on small targets that fly circles around them.