0

I got the error below by using these as my main and class constructor.

#include<Process.h>
int main(int argc, char* argv[])
{
  Process pr (0.01,0.0,argv[3],argv[4],argv[5]);
  return 1;
}

and the process class header:

class Process
{
  public:
    Process();
    Process(double BinSize,double Offset,const std::string& parameters,const std::string& TDBname,const std::string& DDBname);
    virtual ~Process();
};

and the process class source:

Process::Process()
{
//ctor
}
Process::Process(double BinSize,double Offset,const std::string& TDBname,const std::string& DDBname,const std::string& parameters)
{
//ctor
cout<<TDBname;
}

but when I compiling the code by Ubuntu 12.10 I got:

main.cpp:(.text.startup+0xf7): undefined reference to `Process::Process(double, double, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

I have no idea where the hell this error coming from! Thank you in advance.

khikho
  • 319
  • 3
  • 11
  • 6
    I see declaration of c-tor, but where id definition? – ForEveR Apr 25 '13 at 07:52
  • 2
    You have to build and link in the `Process` implementation. – juanchopanza Apr 25 '13 at 07:54
  • 1
    This is a linker error, for more information look [here.](http://stackoverflow.com/questions/5892056/undefined-reference-to-c) – Jim Apr 25 '13 at 07:54
  • @ForEveR I added the definition. – khikho Apr 25 '13 at 08:03
  • Can you put the compilation command you used? – stardust Apr 25 '13 at 08:05
  • Is the destructor implemented somewhere ? – Halim Qarroum Apr 25 '13 at 08:07
  • @HalimQarroum Not yet! but the error is on ctor – khikho Apr 25 '13 at 08:08
  • 3
    apart from the linker error, you will get semantic errors. Look at the order of the parameters in the constructor declaration and its definition - what you pass as a "DDBName" (in your case `argv[5]`) gets evaluated as "parameters" – Arne Mertz Apr 25 '13 at 08:13
  • @khikho if you declare a destructor, you **must** define it, or else you will get linker errors on the destructor as well. Actually, that you don't mention them shows that the code and error you posted might not be what you really have. With your code linked right, I get other errors: http://ideone.com/tvxo4r. Without the cpp linked I get not only the error you mention, but one for the destructor as well: http://ideone.com/M5MZgA – Arne Mertz Apr 25 '13 at 08:19
  • It is just a type conversion missing. Convert the char* to string: std::string str(s); Where s is your const char*. – Walter Macambira Apr 25 '13 at 08:00
  • No, that's definitely not missing, since 1st the conversion is implicit and 2nd he's obviously getting a linker error and not a compiler error. – Christian Rau Apr 25 '13 at 08:04
  • I've tested it but the error still remaining! – khikho Apr 25 '13 at 08:05

0 Answers0