Instead of hand waving and paraphrasing error messages, post a real code. Preferably an Minimal Reproducible Example (MRE). This is the smallest possible COMPLETE code that demonstrates the problem at hand. Leave out everything extraneous and unrelated.
Then, post the complete compiler error messages, not your interpretation of them.