- 1
Why am i getting these error cant understand it
inside code block with its header file and source file gives the error in ClassFile.cpp.it gives the error redefinition of ClassFile::ClassFile(std:: string a,int b,int c)' I don't understand what that means since the course doesn't cover 100% everything. I found a solution to work, but not the way I wanted tho.
9 Réponses
+ 8
Sorry but I can't find what's going on :/
+ 6
I think it's because you defined two classes with the same names, the error says that it is already defined in line 16, so in 40 you can't define a derived class(or any class) with the same name
+ 6
Also the derived class doesn't have any constructor (sorry if I am misundersteanding your code)
+ 5
You have defined the constructor of your class ClassFile twice. Once in your header-file and once in your cpp file. So you only want one definition ( only one constructor body). So you either remove the definition in the cpp file (line 40) or you remove it in the header file, where you only declare it (without body) like so:
ClassFile (string s, int a, int b);
Its typical in C++ when you create a class to put only the class declaration in the header file (declaration means you make functions without bodys) and the definitions in a seperate cpp file, like Class.h and Class.cpp, because if you do not, it could, depending on your compiler, increase the size of your executable significantly ( because foreach header file you include it's defined again)
+ 1
And also the compile time will be shorter if you make for every class a own header and cpp file.
0
I could see why inhere cause it all together in one CPP but I put that in code block and its giving the error inside ClassFile.CPP
0
@Elizabeh its OK its just confusing why it won't work I deleted ClassFile::ClassFile(string a, int b,int c){
}
and it worked but that won't work in code::block it gives errors cause ClassFile.CPP is source file
0
@lulugo thank you for the clarification :) I understand now