-1

I'm a visual studio 2015 c++ newby who's trying to write some game code at home.

I'm getting this link error: LNK2019 unresolved external symbol "public: class std::basic_string,class std::allocator > __thiscall display_utils::fit_int_2(int)" (?fit_int_2@display_utils@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function "public: void __thiscall bat_stats::disp_bat_stats(struct bat_stats::bat_stats_typ)" (?disp_bat_stats@bat_stats@@QAEXUbat_stats_typ@1@@Z)

It apparently doesn't like the string I'm using to access the returned string from function fit_int_2. I've google searched for a solution, but can't find anything that fixes my problem. Note that the code compiled and linked before i I added the fit_int_2 call. Thanks in advance if you can help me out. The code is below:

bat_stats.h

#pragma once

class bat_stats
{
public:
    struct bat_stats_typ
    {
        int gm;
        int ab;
        int ht;
        int dbl;
        int trpl;
        int hr;
        int rbi;
        int sb;
        int cs;
        int bb;
        int ibb;
        int sf;
        int sac;
        int k;
        int gidp;
        int err;
        float ave;
        float slg;
        float obp;
    };
    void disp_bat_hdr();
    void disp_bat_stats( bat_stats_typ );
private:
    int dummy;
};

bat_stats.cpp

#include <iostream>
using std::cout;
std::cin;

#include <string>
using std::string;

#include "bat_stats.h"
#include "display_utils.h"

void bat_stats::disp_bat_hdr()
{
    cout << " G  AB  H  2B 3B HR RBI SB CS BB IW SF SH  K GDP  E  AVE  SLG  OBP\n";
}

void bat_stats::disp_bat_stats( bat_stats_typ bat )
{
    display_utils dut;

    string s;

    s = dut.fit_int_2( bat.gm );         // <- the problem is here!
    cout << s << bat.gm << " ";
    cout << bat.ab << "\n\n";
}

display_utils.h

#pragma once

#include <string>
using std::string;

class display_utils
{
public:
    void insert_5_lines();
    string fit_int_2( int );
private:
    int dummy;
};

display_utils.cpp

#include <iostream>
using std::cout;

#include "display_utils.h"

void display_utils::insert_5_lines()
{
    cout << "\n\n\n\n\n";
}

string fit_int_2(int i0)
{
    string s0 = "";

    if (i0 < 10)
    {
        s0 = " ";
    }
    return s0;
}
Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • 2
    You need to check that your project actually contains `display_utils.cpp`. Writing a .cpp file doesn't do anything -- you have to add it to the Visual Studio project. – PaulMcKenzie Jan 23 '16 at 18:42

1 Answers1

0

You need to change

string fit_int_2(int i0)

to

string display_utils::fit_int_2(int i0)

(You need to define the member function - currently you're defining an unrelated global function.)

Alan Stokes
  • 18,815
  • 3
  • 45
  • 64