Home > Mobile >  Compiler/linker complaining about function definition not found in C
Compiler/linker complaining about function definition not found in C

Time:12-03

I've done this so many times, yet the reason why Visual Studio is complaining about this escapes me.

Manipulator.cpp:

#include "Manipulator.h"

Manipulator::Manipulator() {}
Manipulator::~Manipulator() {}


void proc(std::string p, int f, std::string c)
{
    // switch-case p to c based on f: 

    return;
}

Manipulator.h: (void -proc- has a curly underscore, and that's what's driving me up the wall.)

#ifndef MANIPULATOR_H
#define MANIPULATOR_H
#include <string>

class Manipulator
{
private:

protected:

public:
    Manipulator() ;
    ~Manipulator() ;

    void proc(std::string, int, std::string);
    // function definition for 'proc' not found. 

};

#endif MANIPULATOR_H

main.cpp

#include "Manipulator.h"
...
int main() 
{
    ...
    Manipulator m; 
    ...
    m.proc(opdBMP, fxn, newBMP); 

    return 0; 
}

What is it that VS wants so that I can get a move on? It is telling me that there are two linker errors: LNK2019 and LNK1120 (unresolved external). (I used to keep track of these kinds of errors but lost the file as a log with these.)

CodePudding user response:

The compiler is correct in complaining, because the definition should be

void Manipulator::proc(std::string p, int f, std::string c) {
...
}

You just defined a free function instead of a member of Manipulator.

  • Related