0

I am Using Visual Studios 2012 Ultimate, This is my error and main: the only edit I have made is in the linkedbag.h and node.h I took out a #include linkedbag.cpp and node.cpp respectively at the bottom of the header file Ex:

class blah
{};
#include "blah.cpp"
#endif


//  Created by Tony Chern 9/4/2013
//  Sample code for lab2.cpp

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include "LinkedBag.h"

using namespace std;

void showMenu();
int checkMenuInput(char[]);
void displayBag(LinkedBag<string>& );

int main()
{
    int choice;
    string str;
    LinkedBag<string> bag;

    cout << "Starting the bag with 6 items." << endl;

    string items[] = {"one", "two", "three", "four", "five", "one"};
    cout << "Add 6 items to the bag: " << endl;
    for (int i = 0; i < 6; i++)
    {
        bag.add(items[i]);
    }  // end for



    do
    {   
        showMenu(); //display menu
        cin >> choice; //store user's choice

        //make sure user types in valid menu choice
        while (choice < 1 || choice > 6) 
        {
            cout << "Please enter a valid menu choice: ";
            cin >> choice;
        }

        if (choice != 6) //if user doesn't want to quit program
        {
            switch (choice)
            {
                case 1: //insert item
                    break;

                case 2: //delete item
                    break;
                case 3: //append item
                    cout << "Item name: ";
                    cin >> str;
                    bag.add(str);
                    break;
                case 4: //print list
                    displayBag(bag);
                    break;
                case 5: //reverse list
                    break;

            }
        }
    } while(choice != 6);
    return 0;
}  // end main


// to display the test menu
void showMenu()
{
    cout << "\n"
         << "1. Insert item\n"
         << "2. Delete item\n"
         << "3. Append item\n"
         << "4. Print list\n"
         << "5. Reverse list\n"
         << "6. Quit\n"
         << "Enter your choice: ";      
}

// to validate the user input to menu.
int checkMenuInput(char input[])
{
    int flag = 0; //0 if valid input, 1 if not

        for (int i = 0; i < strlen(input); i++)
        {
            if((isdigit(input[i]) == 0) && (input[i] != '.'))
            {
                flag = 1;
            }
        }
    return flag;
}

void displayBag(LinkedBag<string>& bag)
{
    cout << "The bag contains " << bag.getCurrentSize()
        << " items:" << endl;
   vector<string> bagItems = bag.toVector();

   int numberOfEntries = (int) bagItems.size();
   for (int i = 0; i < numberOfEntries; i++)
   {
      cout << bagItems[i] << " ";
   }  // end for
    cout << endl;
}  // end displayBag


1>------ Build started: Project: Lab2, Configuration: Debug Win32 ------
1>  Node.cpp
1>  LinkedBag.cpp
1>  Lab2.cpp
1>c:\users\omive_000\documents\visual studio 2012\projects\lab2\lab2\lab2.cpp(90): warning C4018: '<' : signed/unsigned mismatch
1>  Generating Code...
1>Lab2.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedBag<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::LinkedBag<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??0?$LinkedBag@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE@XZ) referenced in function _main

1>Lab2.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall LinkedBag<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::~LinkedBag<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??1?$LinkedBag@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@UAE@XZ) referenced in function _main
1>Lab2.obj : error LNK2019: unresolved external symbol "public: virtual bool __thiscall LinkedBag<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::add(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?add@?$LinkedBag@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@UAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>C:\Users\omive_000\documents\visual studio 2012\Projects\Lab2\Debug\Lab2.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
VanyaS
  • 33
  • 9

1 Answers1

1

The implementation of the LinkedBag template class should be visible from the header.

See this question for details.

By removing the include to linkedbag.cpp you broke that condition. That being said, including .cpp files is indeed a quirky thing to do, so you might want to consider to simply move the implementation to the header instead of doing the include here.

Community
  • 1
  • 1
ComicSansMS
  • 51,484
  • 14
  • 155
  • 166