inheritance problem : undefined reference

Hi,

I have a problem with inheritance. It's the first time i use inheritance but i thought i understood it...

I get the following error when i try to compile the code.

/tmp/ccdOBxMZ.o(.text+0x2b): In function `main':
: undefined reference to `child::child()'
/tmp/ccdOBxMZ.o(.text+0x3d): In function `main':
: undefined reference to `child::~child()'
collect2: ld returned 1 exit status
make: *** [all] Error 1



I have a mother class,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class mother{
public: 
  mother::mother(TString);
  mother::~mother();
  protected:
  ifstream filetoread;
  TString filename;
  vector<double> weight;
  vector<double> werror;
};



mother::mother(TString filename){
  
  //weight.push_back(0.8);
  //weight.push_back(0.7);
  //werror.push_back(0.1);
  //werror.push_back(0.3);

  double wei,err;
  //TString filename = "table.txt";
  TString aline="";
  filetoread.open(filename);
  if(!filetoread){
    cerr << "FILE COULD NOT BE OPENED!"<<endl;
  }

  while(aline.ReadLine(filetoread)){

    istringstream istr(aline.Data());
    
    istr >> wei >> err;
    weight.push_back(wei);
    werror.push_back(err);
  }
  
}
mother::~mother(){}




and a child class which inherits mother

1
2
3
4
5
6
7
8
9
10
11
class child : public mother{

public: 
  
  child();
  ~child();
  
  child child::vary(child);
  void proout();

};


1
2
3
4
5
6
7
8
9
10
11
child::child() : ("table.txt"){}
child::~child(){}
child child::vary(child Kind){
  for(int i=0; i < Kind.weight.size() ; i++){
    Kind.weight.at(i) = Kind.weight.at(i)+ Kind.werror.at(i)/2 ;
  }
return Kind;
}
void child::proout(){
  cout << weight.at(0) << endl;
}


I just post all the code, so you see that i actually did define my functions.

It all kinda worked. I just had a problem with the constructors because the compiler had no argument for mother when calling the child constructor. So i looked up the solution and tried what i wrote above:
 
( child::child() : ("table.txt"){} )


That sadly doesn't seem to work. Maybe i have another problem.
Oh Sorry i forgot the main function. It doesn't do anything except creating an child object:

 
child Kind;


There is something which is really strange.

When i create the object with

 
child Kind();


it works, but i get errors when i try to use the functions on Kind:

1
2
  Kind.proout();
  Kind=Kind.vary(Kind);


errors:

main.cc: In function `int main()':
main.cc:19: request for member `proout' in `Kind()', which is of non-aggregate
type `child ()()'
main.cc:20: request for member `vary' in `Kind()', which is of non-aggregate
type `child ()()'
make: *** [all] Error 1


I really appreciate your help.
Thank you very much for reading my wall of text.

Alex
Last edited on
Ok i now found out, that my main function simply doesn't know the functions of child although i included child.hh .
So I included child.cc (I actually thought that the content of child.cc is "loaded" too when I include child.hh) end got another cryptic error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
In file included from main.cc:3:
/usr/include/c++/3.2.3/bits/ios_base.h: In copy constructor 
   `std::basic_ios<char, std::char_traits<char> >::basic_ios(const 
   std::basic_ios<char, std::char_traits<char> >&)':
/usr/include/c++/3.2.3/bits/ios_base.h:424: `std::ios_base::ios_base(const 
   std::ios_base&)' is private
child.cc:9: within this context
/usr/include/c++/3.2.3/streambuf: In copy constructor `std::basic_filebuf<char, 
   std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, 
   std::char_traits<char> >&)':
/usr/include/c++/3.2.3/streambuf:479: `std::basic_streambuf<_CharT, 
   _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) 
   [with _CharT = char, _Traits = std::char_traits<char>]' is private
child.cc:9: within this context
make: *** [all] Error 1



I really hope someone here can help me with this. I'm clueless.
Thank you very much.
Topic archived. No new replies allowed.