Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linker error I can't figure out

Status
Not open for further replies.

swingkyd

Programmer
Jul 10, 2003
34
0
0
CA
Hello, I am having trouble with linker error...
This is my first stab at creating inherited objects. I cannot seem to get them working. I get the following errors:
Code:
busdes.obj : error LNK2001: unresolved external symbol "public: void __thiscall model::openfile(char *,int)" (?openfile@model@@QAEXPADH@Z)
Debug/bus_program.exe : fatal error LNK1120: 1 unresolved externals [\code]

I've created objects: model & UserInput
(edited code)

[code]  // "model.h"
#ifndef BP_MODEL_H
#define BP_MODEL_H
#include<fstream.h>
class model{
public:
  model();
  void openfile(char*, int);        // opens file &quot;char*&quot; and ignores &quot;int&quot; lines 
};
#endif [\code]

I have a model.cpp file that includes this file with the function: 
[code]openfile(char* filename, int lines){cout<<&quot;test\n&quot;;&quot;[\code]

The code for the child goes something like this:
[code] // &quot;UserInput.h&quot;
#ifndef BP_USERINPUT_H
#define BP_USERINPUT_H
#include <iostream.h>
#include <iomanip.h>
#include &quot;model.h&quot; // needed because of ifndef... 
class UserInput: public model{public: int a=1;};
#endif [\code]
and main goes something like this:
[code]
#include<cstring>
#include<iostream.h>
#include<iomanip>
#include &quot;model.h&quot;
#include &quot;UserInput.h&quot;
int main(){
UserInput ui1; 
ui1.openfile(&quot;myfile.txt&quot;, 0);
return(0);
}

Help would be GREATLY appreciated. I have no idea why this doesn't work.
 
I have a model.cpp file that includes this file with the function:
openfile(char* filename, int lines){cout<<&quot;test\n&quot;;&quot;
Code:
void model::openfile(char* filename, int lines){cout<<&quot;test\n&quot;;}

-pete
 
pete:
I caught that...I just forgot to write that in...

I still get the same error...
 
my problem has mysteriously fixed itself. I believe it had something to do with the header files being traversed more than once...

I just playted around with them until it worked.

Basically, I think that 'model.h' was defined more than once so there were troubles with linking at the end of the day
 
Perhaps the model.cpp file is not installed in the project and is not being built?

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top