linking source files
<p>I am trying to break up a program I have written into two source files but I am having trouble linking them and the error messages aren't making any sense to me.</p>

<p>I will provide a shortened version of the files with relevant information:</p>

<pre><code>//grandiose.cpp:

#include "thingy.h"

int main() {}

//thingy.h:
#include&lt;string&gt;
int add (int x, int y);
char * parse_input_fragment(const string &amp; ,const string &amp; , size_t &amp;, size_t &amp;);

//thingy.cpp:
#include "thingy.h"

int add (int x, int y)
{
    return x+y;
}

char * parse_input_fragment(const string &amp; objective,const string &amp; input, size_t &amp; first_finder, size_t &amp; second_finder) {
    char * string_to_int_buffer = new char[64];
    first_finder = input.find(objective, first_finder);
    first_finder = (input.find('=', first_finder))+1;
    second_finder = input.find(';', first_finder);
    int y = 0;
    for(unsigned int x = first_finder; x &lt; second_finder; x++) {
        if (  (input[x] != ' ') &amp;&amp; (input[x] != '\n') ) {
            string_to_int_buffer[y] = input[x];
            y++;
        }
    }
    string_to_int_buffer[y] = '\0';
    first_finder = second_finder;
    return string_to_int_buffer;
}
</code></pre>

<p>The parse_input_fragment function compiles fine if I put it in grandiose.cpp but i get error messages when I split it up as described. I included the "add" function for testing purposes and that one compiles fine. </p>

<p>The error message I get is for the prototype in thingy.h:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int</p>

<p>It's clearly marked as a character pointer return type and works when not split out of grandiose.cpp, so I am quite confused as to the problem here.</p>

<p><strong>EDIT:</strong></p>

<p>Ok, after moving the using namespace std; to the appropriate place and included the header guards as recommended those error messages disappeared but I am getting new ones which I am further confused about. I'll include the complete files and the error messages.</p>

<p>Error messages:
province.obj : error LNK2005: "public: __thiscall province::province(void)" (??0province@@QAE@XZ) already defined in grandiose.obj</p>

<p>province.obj : error LNK2005: "public: __thiscall province::province(class std::basic_string,class std::allocator >,int * const)" (??0province@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAH@Z) already defined in grandiose.obj</p>

<pre><code>    // grandiose.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include &lt;vector&gt;
    #include &lt;ctime&gt;
    #include &lt;iostream&gt;
    #include &lt;fstream&gt;
    #include &lt;string&gt;
    #include "market.h"

    int _tmain(int argc, _TCHAR* argv[])
    {
        market England;
        ifstream reader;
        reader.open ("provinces.txt", ios::in);
        if (reader.is_open()) {  //check if txt file successfully opened
            cout &lt;&lt; "\n\nprovinces.txt was successfully opened.\n\n";
        }
        else {
            cout &lt;&lt; "\n\nfile was not successfully opened.\n\n";
            return (1);
        }
        string reader_buffer;
        while ( reader.good() ) { // while not end of file
            getline (reader, reader_buffer, '}'); // get one province's worth of data from txt file
            if (!reader_buffer.empty()) {
                parse_provinces (reader_buffer); // send data to be parsed
            }
        }
        add(1,2);
        return 0;
    }


    //market.h

    #include &lt;iostream&gt;
    #include &lt;list&gt;
    #include "province.h"
    using namespace std;

    class market
    {
        public:
        list&lt;province&gt; provinces;
    };

    //province.h

    #ifndef PROVINCE_H
    #define PROVINCE_H
    #include &lt;iostream&gt;
    #include &lt;string&gt;

    using namespace std;

    int add (int x, int y);
    char * parse_input_fragment(const string &amp; ,const string &amp; , size_t &amp;, size_t &amp;);

    class province
    {
    public:
        province::province();
        province::province(string, int[]);
        unsigned int * rural_poor;
        unsigned int * urban_poor;
        unsigned int * max_mine_jobs;
        unsigned int * max_farm_jobs;
        unsigned int * employed_mine;
        unsigned int * employed_farm;
        unsigned int * employed_factory;
        string name;
    };
    province::province () {
        rural_poor = new unsigned int(0);
        urban_poor = new unsigned int(0);
        max_mine_jobs = new unsigned int(0);
        max_farm_jobs = new unsigned int(0);
        employed_mine = new unsigned int(0);
        employed_farm = new unsigned int(0);
        employed_factory = new unsigned int(0);
        name = "";
    }
    province::province (string name, int numbers[]) {
        province::name = name;
        cout &lt;&lt; "This province is named " &lt;&lt; province::name &lt;&lt; endl;
        rural_poor = new unsigned int(numbers[0]);
        cout &lt;&lt; "Rural poor = " &lt;&lt; *rural_poor &lt;&lt; endl;
        urban_poor = new unsigned int(numbers[1]);
        cout &lt;&lt; "Urban poor = " &lt;&lt; *urban_poor &lt;&lt; endl;
        max_mine_jobs = new unsigned int(numbers[2]);
        cout &lt;&lt; "Max mine jobs = " &lt;&lt; *max_mine_jobs &lt;&lt; endl;
        max_farm_jobs = new unsigned int(numbers[3]);
        cout &lt;&lt; "Max farm jobs = " &lt;&lt; *max_farm_jobs &lt;&lt; endl;
    }

    province * parse_provinces(string);

    #endif

    //province.cpp

    #include "stdafx.h"
    #include "province.h"

    int add (int x, int y)
    {
        return x+y;
    }

    char * parse_input_fragment(const string &amp; objective,const string &amp; input, size_t &amp; first_finder, size_t &amp; second_finder) {
        char * string_to_int_buffer = new char[64];
        first_finder = input.find(objective, first_finder);
        first_finder = (input.find('=', first_finder))+1;
        second_finder = input.find(';', first_finder);
        int y = 0;
        for(unsigned int x = first_finder; x &lt; second_finder; x++) {
            if (  (input[x] != ' ') &amp;&amp; (input[x] != '\n') ) {
                string_to_int_buffer[y] = input[x];
                y++;
            }
        }
        string_to_int_buffer[y] = '\0';
        first_finder = second_finder;
        return string_to_int_buffer;
    }

    province * parse_provinces(string input) {
        size_t first_finder;
        size_t second_finder;
        char * string_to_int_buffer;
        int population_info[4];


        // find the name
        first_finder = input.find('=');
        string name;
        for(unsigned int x = 0; x &lt; first_finder; x++) {
            if ((input[x] != ' ') &amp;&amp; (input[x] != '\n')) {
                name.push_back(input[x]);
            }
        }

        // find the rural poor
        string_to_int_buffer = parse_input_fragment("rural_poor", input, first_finder, second_finder);
        population_info[0] = atoi(string_to_int_buffer);

        // find the urban poor
        string_to_int_buffer = parse_input_fragment("urban_poor", input, first_finder, second_finder);
        population_info[1] = atoi(string_to_int_buffer);

        // find max mine jobs
        string_to_int_buffer = parse_input_fragment("max_mine_jobs", input, first_finder, second_finder);
        population_info[2] = atoi(string_to_int_buffer);

        // find max farm jobs
        string_to_int_buffer = parse_input_fragment("max_farm_jobs", input, first_finder, second_finder);
        population_info[3] = atoi(string_to_int_buffer);

        delete[] string_to_int_buffer;
        string_to_int_buffer = NULL;
        province * current_province = new province(name, population_info);
        return current_province;
    }
</code></pre>
