C++编译报错:类sala中未声明成员函数inici求助
sala::inici That error tells us the compiler can't find the declaration of inici(int, int) in your sala class, even though you’ve clearly added it to the header. Let’s walk through the most likely fixes tailored to your situation:
Make sure you saved your
sala.hhfile: It’s an easy oversight—if you added theinicideclaration but didn’t save the header before compiling, the compiler will still use the old version without that function. Hit save and recompile.Do a clean build: Sometimes build systems (like Makefiles) fail to detect changes to header files, reusing old compiled object files instead. Delete any
.oor.objfiles generated from your code, then recompile everything from scratch. This ensures the compiler picks up the latest version of your header.Confirm you’re including the correct header: If there are multiple copies of
sala.hhin different directories, your compiler might be picking up an older version that lacks theinicifunction. Double-check that the#include "sala.hh"line insala.ccpoints to the file you edited (this is usually non-issue if they’re in the same folder, but worth verifying).Check for hidden syntax errors: A missing semicolon or brace earlier in the header could cause the compiler to misparse the class definition. Your private section and constructor/destructor declarations look correct, but it’s worth a quick second pass to ensure no typos are hiding the
inicideclaration.
Since your posar_prod function compiles fine, we know the header is being included correctly in sala.cc. The problem is almost certainly related to the compiler not seeing the updated inici declaration in the header—starting with saving the file and doing a clean build should resolve this quickly.
内容的提问来源于stack exchange,提问作者minoru

