Linker Error?

For some reason my code is failing to compile for the do while loop on ending on line 58. I'm getting errors:

[Linker error] undefined reference to `copyLine(std::basic_ifstream<char, std::char_traits<char> >&, std::basic_ofstream<char, std::char_traits<char> >&)'

and
ld returned 1 exit status


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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string> 
using namespace std;

#define hisFamily "The Adopted.txt"            //His family
#define herFamily "The Originals.txt"          //Her family
#define ourFamily "The Big Picture.txt"        //Our family

//Function Prototypes
//Copies text
int copyLine(ifstream&, ofstream&);

int main()
{   
    ifstream theAdopted("The Adopted.txt");
    ifstream theOriginals("The Originals.txt");
    ofstream theBigPicture("The Big Picture.txt");
    
    int SIZE1 = 200, SIZE2 = 200;  
    int insA[SIZE1]; 
    int insB[SIZE2];
    int outs[SIZE1 + SIZE2];
    int lineCount;
    int index1 = 0; 
    int index2 = 0;
    int A = 0;
    int B = 0;
    
    //Retreive his family's grades.
    theAdopted.open(hisFamily);
    if(theAdopted.fail())
    {
        cerr << "ERROR: Cannot open" << theAdopted << ". \n";
        return EXIT_FAILURE;
    } 
    //Retreive her family's grades.
    theOriginals.open(herFamily);
    if(theOriginals.fail())
    {
        cerr << "ERROR: Cannot open" << theOriginals << ". \n";
        return EXIT_FAILURE;
    }
    //Call theBigPicture.
    theBigPicture.open(ourFamily);
    if(theBigPicture.fail())
    {
        cerr << "ERROR: Cannot open" << theBigPicture << ". \n";
        return EXIT_FAILURE;
    }        
    //Copy data hisFamily to ourFamily.
    lineCount = 0;
    do
    {
       if(copyLine(theAdopted, theBigPicture) != 0)
       lineCount++;
    }while(!theAdopted.eof());                     //***ERROR HERE***           
    
    cout << "Input data mergered to file 'The Big Picture.exe'." << endl;
    //Close files.
    theAdopted.close();
    theOriginals.close();
}  
Did you forget to actually implement the copyLine function?
I have my copyLine function now, but it's giving me the same error. Am I doing this wrong?

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string> 
using namespace std;

#define hisFamily "The Adopted.txt"            //His family
#define herFamily "The Originals.txt"          //Her family
#define ourFamily "The Big Picture.txt"        //Our family

//Function Prototypes
//Copies text
int copyLine(ifstream&, ofstream&);

int main()
{   
    ifstream theAdopted("The Adopted.txt");
    ifstream theOriginals("The Originals.txt");
    ofstream theBigPicture("The Big Picture.txt");
    
    int SIZE1 = 200, SIZE2 = 200;  
    int insA[SIZE1]; 
    int insB[SIZE2];
    int outs[SIZE1 + SIZE2];
    int lineCount;
    int index1 = 0; 
    int index2 = 0;
    int A = 0;
    int B = 0;
    
    //Retreive his family's grades.
    theAdopted.open(hisFamily);
    if(theAdopted.fail())
    {
        cerr << "ERROR: Cannot open" << theAdopted << ". \n";
        return EXIT_FAILURE;
    } 
    //Retreive her family's grades.
    theOriginals.open(herFamily);
    if(theOriginals.fail())
    {
        cerr << "ERROR: Cannot open" << theOriginals << ". \n";
        return EXIT_FAILURE;
    }
    //Call theBigPicture.
    theBigPicture.open(ourFamily);
    if(theBigPicture.fail())
    {
        cerr << "ERROR: Cannot open" << theBigPicture << ". \n";
        return EXIT_FAILURE;
    }        
    //Copy data hisFamily to ourFamily.
    lineCount = 0;
    do
    {
       if(copyLine(theAdopted, theBigPicture) != 0)
       lineCount++;
    }while(!theAdopted.eof());
    
    cout << "Input data mergered to file 'The Big Picture.exe'." << endl;
    //Close files.
    theAdopted.close();
    theOriginals.close();
    return 0;
}  
int copyLine
    (ifstream& theAdopted,
     ifstream& theOriginals,
     ofstream& theBigPicture)
     {
         const char NWLN = '\n';
         char nextCh;
         int charCount = 0;
         
         //Merge
         theAdopted.get(nextCh);
         while ((nextCh != NWLN) && !theAdopted.eof())
         {
             theBigPicture.put(nextCh);
             charCount++;
             theAdopted.get (nextCh);
         }
         if(!theAdopted.eof())
         {
             theBigPicture.put(NWLN);
             charCount++;
         }
         return charCount;
     }
                 
The declaration and definition don't match.

declaration has two parameters
int copyLine(ifstream&, ofstream&);

You call with two parameters
if(copyLine(theAdopted, theBigPicture) != 0)

definition has three parameters
int copyLine(ifstream& theAdopted,ifstream& theOriginals, ofstream& theBigPicture)
Last edited on
Yeah, I was confused. Can I give the declaration function and if statement 3 parameters?? If so, would it be correct to write
int copyLine(ifstream&, ifstream&, ofstream&);
or
int copyLine(ifstream& theAdopted,ifstream& theOriginals, ofstream& theBigPicture);?

And for the if statement, can I write
if(copyLine(theAdopted, theOriginals, theBigPicture) != 0)?
closed account (j3Rz8vqX)
Is it implementable? yes.

It's functionality is what you make of it.

Just ensure that the definition and the declaration are the same:
http://www.tutorialspoint.com/cplusplus/cpp_functions.htm
Okay, great. It's compiling now that I've altered. But, do yall know whether I need to save my .txt files in a program file for DEV like I would NetBeans or CodeBlocks?? I'm not sure if DEV can locate the files...
Topic archived. No new replies allowed.