I divided my program into three files. All of them are in the same folder and run in the g ++ compiler as g++ main.cpp pkv.cpp pkv.h

But it gives an error - most likely, I incorrectly filled in the pkv.cpp files pkv.h. If you write the function to_dec() just in main.cpp , then everything works

Do not look at the code much: I have it different, but this is a simplified model.

 //main.cpp // // #include <iostream> #include "pkv.h" using namespace std; int main(int argc, char* argv[]) { string example = "1 5 20 15 3 -6 -19" double res_dec = to_dec(example); //TO_DEC() - требуемая функция cout << "RESULT in DECIMAL: " << setprecision(30) << res_dec << endl; return 0; } 

Second file

 // pkv.cpp // // #include <iomanip> #include <cmath> #include <string> double to_dec(string pkv) { double decimal; short sign = atoi(pkv.substr(0, 1).c_str()); for (int i = 0; i < 2; i++) { pkv.erase(0, pkv.find(' ') + 1); } while (pkv.find(' ') != -1) { decimal += pow(2, atoi(pkv.substr(0, pkv.find(' ')).c_str())); pkv.erase(0, pkv.find(' ') + 1); } decimal += pow(2, atoi(pkv.c_str())); return pow(-1, sign) * decimal; } 

And third

 // pkv.h // // #ifndef PKV_H #define PKV_H double to_dec(string pkv); #endif 

Closed due to the fact that off-topic participants VTT , freim , aleksandr barakin , 0xdb , LFC March 3 at 8:35 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - VTT, aleksandr barakin, LFC
  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - freim, 0xdb
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    g++ main.cpp pkv.cpp should be enough - well, in terms of - the header files need not be compiled separately ... - Harry g++ main.cpp pkv.cpp
  • one
    The compiler does not need to transfer the header file, it only needs to know where to find it - Andrej Levkovitch 6:19 pm
  • And what a mistake? - Andrej Levkovitch
  • @AndrejLevkovitch PKV.H: ERROR: MAIN.CPP: ERROR: 'to_dec' PS I’ve already started without pkv.h - february 6:24 pm
  • one
    pkv.h , std::string used in main.cpp and pkv.h , but there is no #include <string> . - VTT

1 answer 1

1) a certain string is used in your header. What it is - the compiler can not be known.

2) your cpp file with the definition of your function does not refer to your header file with the function declaration

3) the compiler has already written this to you. Why do not you read what he tells you a mystery.