Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:26:02+00:00 2026-06-11T16:26:02+00:00

I have been encountering a linker error when attempting to call a class method

  • 0

I have been encountering a linker error when attempting to call a class method from my main method. I have searched for an answer but nothing seems applicable to my issue, any help will be much appreciated.

FileSystem.h

#ifndef FILE_SYSTEM_H
#define FILE_SYSTEM_H

#include <fstream>
#include <string>
#include <random>

#include "SortingAlgorithms.h"
#include "SortingAlgorithms.cpp"

using namespace std;

class FileSystem
{
private:
    ifstream inFile;
    ofstream outFile;

    template <class T>
    void fillArrays( T randomArray[], T sortedArray[], T backwardArray[], int size );

public:
    FileSystem();
    ~FileSystem();

    bool openFile(string fileName);
    void writeToFile(string output);
    void createTestFiles(string testFiles[]);

    template <class T>
    void fillArrayFromFile(T list[], int size);
};

#endif

fillArrayFromFile

template <class T>
void FileSystem::fillArrayFromFile(T list[], int size)
{
    int i;

    for(i = 0; i < size; i ++)
    {
        inFile >> list[i];
    }

    inFile.clear();
    inFile.seekg(inFile.beg);
}

pa2.cpp

#include <iostream>
#include <ctime>
#include <string>
#include <iomanip>

#include "TimerSystem.h"
#include "FileSystem.h"

using namespace std;

int main()
{
    FileSystem file;
    int testArray[10];

    file.openFile("test-10-0.txt");
    file.fillArrayFromFile(testArray, 10);
}

Error:

pa2.obj : error LNK2019: unresolved external symbol "public: void __thiscall FileSystem::fillArrayFromFile<int>(int * const,int)" (??$fillArrayFromFile@H@FileSystem@@QAEXQAHH@Z) referenced in function _main
C:\Users\Matt\Google Drive\Programming\Data Structures & Algorithms\PA2-9-15-2012\Debug\PA2.exe : fatal error LNK1120: 1 unresolved externals

Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:26:03+00:00Added an answer on June 11, 2026 at 4:26 pm

    When compiling code that calls a template function, the compiler must be able to see the full implementation of the function. At the point the compiler is building pa2.cpp, the compiler is only looking at FileSystem.h and the definitions within the header file (and other header files included from pa2.cpp, of course). It does not look at the contents of FileSystem.cpp at that point.

    To fix this, move the implementation of FileSystem::fillArrayFromFile() to the header file instead of the .cpp file. You can do that one of two ways:

    class FileSystem {
    public:
        template <class T>
        void fillArrayFromFile(T list[], int size);
    };
    
    template <class T>
    void FileSystem::fillArrayFromFile(T list[], int size)
    {
        // ...
    }
    

    or

    class FileSystem {
    public:
        template <class T>
        void fillArrayFromFile(T list[], int size)
        {
            // ...
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been playing around with the canvas element, but are encountering sluggishness on
I have been encountering this error for my project, which involves working with Digital
recently I have been encountering problems with exposing events from .NET to COM. I
iPhone - 5.1(9B176) I have been encountering inconsistent behaviour in overlaying a mask view
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Have been reading about async and tasks and been attempting to convert the CopyFileEx
Have been searching how to convert a dictionary to a string. But the results
I have been encountering an issue with inserts in EF 4.0. During a migration
I've been trying to get an existing project working on local copy but have
I have been encountering issues with a custom WCF service deployed to SharePoint 2010.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.