I am trying to build a solution in Visual Studio and the compiler keeps throwing the error: "missing type specifier- int assumed. Note: C++ does not support default-int" in my "exercise13class.h" file on the line where the constructor is initialized. I have looked up the error and it sounds like it may have something to do with circular dependency. I have looked over my code and read about circular dependency but I still feel confused as to what I am doing incorrectly. Is it that my header file declares a template that my main cpp file has to define? Does anyone know what is going on here?
Why do you appear to have two files named exercise13class.h?
By the way when dealing with templates you need to make sure both the definition and the declaration are in the same compilation unit. This usually means that the whole class is in a single header file.
@jib- I thought having the declarations and definitions for a class in separate files was beneficial so that if multiple files are instantiating objects based off of the same class file the linker won't throw any errors because of multiple definitions. I might be wrong and I might be misunderstanding how that works. I was under that impression because of a recent post I made:http://www.cplusplus.com/forum/general/248394/. See specifically the discussion between @TheIdeasMan and me.
@Peter87- wouldn't putting <vector> in exercise13class.h mean that when exercise13.cpp imports the exercise13class.h header file that <vector> will be imported twice and the complier or linker will throw an error? I might be misunderstanding how importing those standard library classes works.
The header <vector> may be included any number of times; the effect is as if it was included just once.
A translation unit may include library headers in any order. Each may be included more than once, with no effect different from being included exactly once... http://eel.is/c++draft/using.headers#2
I thought having the declarations and definitions for a class in separate files was beneficial
When you're dealing with non-template classes this is true. However when working with template classes both the class definition and the class implementation must be in the same compilation unit. This usually leads to template classes being defined and implemented in a single header file.
so that if multiple files are instantiating objects based off of the same class file the linker won't throw any errors because of multiple definitions.
Template classes are different, basically they are created inline for every instance of the template class.
We shouldn't be defining objects or non-inline functions with external linkage in a header file.
Then, with header guards, multiple inclusion would not cause a problem.
Thanks everyone else for helping me understand all of this stuff. My program runs as expected both in Visual Studio and when I compile it in my Unix terminal.