0

I am a C++ noob and dont know why I already get an error considering that I havent even done anything.

Here is my code

//in .h
#include <observers/variant/TimestampVariant.h>
class Record
    {
    public:
        Record();

    private:
        observers::TimestampVariant stamp;
    };

and in .cpp is basically nothing yet

#include <observers/variant/TimestampVariant.h>

    Record::Record()
    {
    }

the scope and the include are correct as far as I can tell (TimestampVariant and stamp have the correct color and TimestampVariant seems correctly linked. When I compile I get the error:

error: undefined reference to `observers::TimestampVariant::TimestampVariant()'

The line which causes the error is

   Record:Record()

Why am I getting already an error? Can you tell me why I am getting this error?

Peter111
  • 803
  • 3
  • 11
  • 21
  • 1
    `Record:Record` and `oberservs::TimestampVariant` are those typos in the question or your original code? Either way plz fix, but please copy past to avoid them next time (they can derail comments/answers). – Borgleader Jan 14 '16 at 14:11
  • You are likely to get this error because you do not include neccessary libraries/object files when linking. However, without knowing your environment it is hard to give more detailed answer. – SergeyA Jan 14 '16 at 14:12
  • Is `TimestampVariant` default constructable? – NathanOliver Jan 14 '16 at 14:13
  • 1
    You are not linking the object file that contains `observers::TimestampVariant::TimestampVariant()` into your final executable. Why this is the case and how it can be fixed depend on your toolchain. Which one do you use ? – Quentin Jan 14 '16 at 14:16
  • @NathanOliver TimestampVariant has a default constructor TimestampVariant(); and another constructor TimestampVariant(long timestamp); – Peter111 Jan 14 '16 at 14:18
  • @Peter111 You still need to link their definitions though. – πάντα ῥεῖ Jan 14 '16 at 14:19
  • @Quentin Sadly I have no idea what a toolchain is. I use QT Creator if this helps – Peter111 Jan 14 '16 at 14:20
  • @Peter111 your toolchain is the set of programs that together produce an executable from your source code. For example, [source code] -> `cpp` -> [preprocessed source] -> `gcc` -> [object files] -> `ld` -> [executable]. I don't know what Qt Creator uses by default, but you should be able to configure it so it finds the missing `.cpp` file. – Quentin Jan 14 '16 at 14:24
  • @Peter111 A _toolchain_ is the collection of compiler, linker and other programs you need to create your final executable target. – πάντα ῥεῖ Jan 14 '16 at 14:24

0 Answers0