Undefined reference to ClassName::ClassName?

The reason for splitting code into header- and source-files is so that the declaration and the implementation are separated. The compiler can translate the source-file (compilation unit) into an object file, and other compilation-units that want to use the classes and functions just include the header-file, and link the object file. This way, the code has to be compiled only once, and can be reused by linking it.

The reason for splitting code into header- and source-files is so that the declaration and the implementation are separated. The compiler can translate the source-file (compilation unit) into an object file, and other compilation-units that want to use the classes and functions just include the header-file, and link the object file. This way, the code has to be compiled only once, and can be reused by linking it.

The problem with templates is that, as long as there are no parameters provided for them, the compiler cannot compile them. The same template instantiated with different parameters results in different types. Std::vector and std::vector are, from the compilers perspective, not related in any way.

Because of this, template-classes usually have to reside completely in a header-file, because, when the template is used, the compiler needs the complete definition in order to generate the class depending on the parameters. As @Gabriel Schreiber pointed out in his answer, you can tell the compiler that he should compile the template with a specific set of parameters, making that available to other compilation units just by linking. However, this does not make the template available for other parameter sets.

Thanks for your comprehensive answer! – CFP Sep 21 '10 at 16:59.

Basically all templated code should be defined in a header, otherwise it will not be built since nothing uses it in the compiled unit. Each cpp file is compiled as a separate unit, and thus constructor and destructor are not compiled. The compiler has no way of knowing what type of template argument you will use in main.

Cpp when it compiles TimeSeries.cpp.

– CFP Sep 19 '10 at 7:50 @CFP: May sound strange but for templates, that’s (unfortunately) the way to go. – Konrad Rudolph Sep 19 '10 at 11:10.

You need to add this in your . Cpp-file (below the definitions): template class TimeSeries; When the compiler compiles TimeSeries. Cpp it doesn't know which for which types the template is need because it is used in another source file.

You need to tell the compiler explicitly. Read about Explicit Template Instantiation in your copy of the Stroustrup or on the internet.

ASIO is a C library. The nm output you posted suggests that you compiled it as C++ code. See how the names are mangled?

That looks like what you'd expect if you compiled C code as C++. Perhaps you accidentally compiled the ASIO code as C++? If you're not sure, post the transcript of building the library for us.

I am not sure about ASIO being C library. I donwloaded the SDK and all the files are pretty much .cpp. But their headers are ordinary .

H and they look like C headers (no fancy C++ stuff). Library compiling used g++: g++ -O0 -g3 -Wall -c -fmessage-length=0 -D_WIN64 -DWINVER=0x0601 -o src\asio. O ..\src\asio.

Cpp How do I do that the library is usable in C projects? – Jakub Zaverka Nov 12 at 18:01.

Forgot to add the files to QT Designer. Solved!

Now just click that green arrow to mark this as "the" answer. – GMan Feb 20 '10 at 19:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions