5
donuts
7y

Help... what is wrong with this?

I trying to make a Runner.cpp so can run different programs in the same project.

Why is this static thing not working?

Comments
  • 6
    In motto.cpp it should be int Motto::run( ){}

    You need to specify that your implementation of the run method is from your Motto class. If not run is just a method flying around (not member of the Motto class class). At least I guess
  • 4
    Unresolved external symbol usually means that you call a declared function that is not defined. In this case its not defined because you are not specifying what class your run method in Motto.cpp should be in
  • 4
    Oh and also could you please use
    #ifndef MYCLASSNAME_H
    #define MYCLASSNAME_H
    at the top of your header file and
    #endif
    at the bottom as include guards instead of
    #pragma once
    ?

    Just so I can sleep well tonight
  • 0
    @b3b3 then, what does that do?

    That was just whatever VS put in...I didn't change anything
  • 1
    @billgates include guards prevent redefinition of global vars/funcs etc. So the stuff inside your header only gets defined once and after that not anymore. At least I understood it like that xD you could try including your header multiple times and just see what happens with or without include guards
  • 0
    @b3b3 I thought '#pragma once' was essentially shorthand for that though, since it only allows the file to be included once. What's the difference?
  • 0
    just needed an example that works..

    It's like Python scripts vs classes it seems and **also the cpp needs to link to the header**

    http://p2p.wrox.com/c-programming/...
  • 0
    @alcamore idk I'm using the other one only. Never had problems with it so I'm not going to change. If you're too lazy to write 3 lines more then you can obviously use that pragma once thingie
  • 0
    @b3b3 looked into it a bit, found a short article about it if you're interested.

    https://msdn.microsoft.com/en-us/...
  • 5
    @alcamore as far as I know #pragma once is not always supported by compilers and the whole #define thing is just cleaner, because you declare the beginning and the end and everything, you could compare it to not writing brackets and writing brackets
Add Comment