C ++ compiling .o file without .cc file

I have a program when I was provided with a compiled .o file, but I do not have the original .cc file, and I only have a ready-made header file on the half side. The header file contains all method signatures, but no private variable declarations. I'm trying to get this .o file to work with a project, but get a segmentation error in the constructor of the class defined by the .o file. The program is compiled. How do I make this work? The program is homework, and the teacher does not want us to see the .cc file. My teacher also knows about the problem. I'm just trying to figure it out on my own (and hopefully with the help of you guys :)). I thought I used to do this with another teacher, but I had no problems. There is a makefile that is used to compile the program.

+4
source share
1 answer

If you are using a C ++ program and the header file includes class definitions, the class definitions must exactly match those used for the initial assembly of the file. This is one rule of definition . If your professor has deleted private variable declarations from class definitions, you are likely to run into crashes; this is because your different .o files will not agree with the size of the objects defined by these classes.

If your professor wants to hide the implementation of the class, he should use the p / impl pattern . If you want to use the header file, you must completely remove the class definitions that are defined and not try to use them (you can use the direct definition, as in class Foo; to satisfy any functions that accept / return the class as a pointer parameter, however).

+4
source

All Articles