0

It looks basic and it’s probably due to a beginner mistake but I can’t figure out why...

When compiling I get an error like below from int main(): “undefined reference to 'Hello::World::PaintService::PaintService()"

paint.cpp

using namespace Hello;
int main(int argc, char **argv) {
    World::PaintService service;
     service.start_painting(argc[1]);

}

PaintService and start_painting are defined like below:

paint_service.h

namespace Hello {
namespace World {
    class PaintService {
        public:
            PaintService();
            void start_painting(...);
}; } }

paint_service.cpp

namespace Hello { 
namespace World {
    void start_painting(....) {
        ... //paint
    }
} }

It seems simple to call that start method like service.start_paint() in another class after calling PaintService service, but something is wrong. I have tried lots of variations yet couldn’t figure out :-/ Could someone point out what I’m doing wrong?

Thanks!

1 Answers1

1

To declare a method, you need to include the name of the class.

namespace Hello {
namespace World {

void PaintService::start_painting(....) { ... }
void PaintService::PaintService() { ... }

}  // namespace World
}  // namespace Hello

https://repl.it/repls/PunySaneSpools#main.cpp

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • Thank you so much!!! This did it!!! But for some reason I had to take out the constructor (PaintService();) from both header file and cpp file... – user2465084 Oct 14 '20 at 04:39