Advertisement

05.13.2006 at 11:04AM PDT, ID: 21849454
[x]
Attachment Details

Unresolved external symbol

Asked by Uzibat in C++ Programming Language

Tags: external, symbol, unresolved

Hi

I'm new to C++ programming (although I have programmed in other languages) and am just trying to teach myself how to do basic classes. I have some very simple code which asks users for input on their favourite and worst CDs and stores these in two objects of class CD (which I've created). Now I want to add some extra functions to my main program so have declared the favourite and worst CDs as global variables but when I do, I'm getting the following error....

CDClassTest.obj : error LNK2001: unresolved external symbol "public: __thiscall CD::CD(void)" (??0CD@@QAE@XZ)
Debug/ClassExperiments.exe : fatal error LNK1120: 1 unresolved externals

My code is as below....


#include <iostream>
#include <string>
#include "CD.H"

using namespace std;

CD myFavouriteCD;  //global declarations of myFavouriteCD and myWorstCD so that other functions can use them
CD myWorstCD;

string getNameOfArtist()
{
      string inputArtist;
      cout<<"\nPlease enter name of artist: ";
      getline(cin, inputArtist);
      return inputArtist;
}

string getNameOfAlbum()
{
      string inputAlbum;
      cout<<"\nPlease enter title of album: ";
      getline(cin, inputAlbum);
      return inputAlbum;
}

int getNoOfSongs()
{
      int inputNoOfTracks;
      cout<<"\nPlease enter number of tracks : ";
      cin>>inputNoOfTracks;
      return inputNoOfTracks;
}

int getYearOfAlbum()
{
      int inputYear;
      cout<<"\nPlease enter year of album : ";
      cin>>inputYear;
      return inputYear;
}

void modifyFavouriteCD()
{
      //need to modify so that it repeats the question until it gets a valid answer
      int fieldToChange;

      cout<<"Which field do you wish to change? Press 1 for artist, 2 for album name, 3 for number of tracks and 4 for year of album : ";
      cin>>fieldToChange;

      switch(fieldToChange)
      {
      case 1:
            myFavouriteCD.setArtist(getNameOfArtist());
            break;
      case 2:
            myFavouriteCD.setTitle(getNameOfAlbum());
            break;
      case 3:
            myFavouriteCD.setNoOfTracks(getNoOfSongs());
            break;
      case 4:
            myFavouriteCD.setYear(getYearOfAlbum());
            break;
      default:
            cout<<"Not a valid choice";
      }
}

void modifyWorstCD()
{
      //need to modify so that it repeats the question until it gets a valid answer
      int fieldToChange;

      cout<<"Which field do you wish to change? Press 1 for artist, 2 for album name, 3 for number of tracks and 4 for year of album : ";
      cin>>fieldToChange;

      switch(fieldToChange)
      {
      case 1:
            myWorstCD.setArtist(getNameOfArtist());
            break;
      case 2:
            myWorstCD.setTitle(getNameOfAlbum());
            break;
      case 3:
            myWorstCD.setNoOfTracks(getNoOfSongs());
            break;
      case 4:
            myWorstCD.setYear(getYearOfAlbum());
            break;
      default:
            cout<<"Not a valid choice";
      }
}

void modify()
{
      //need to modify so that it repeats the question until it gets a valid answer
      int modifyChoice =0;
      
      cout<<"Which CD do you wish to modify? Press 1 for favourite or 2 for worst : ";
      cin>>modifyChoice;

      switch(modifyChoice)
      {
      case 1:
            modifyFavouriteCD();
            break;
      case 2:
            modifyWorstCD();
            break;
      default:
            cout<<"Not a valid choice";
      }
}

void main()
{
      //get input for first class
      cout<<"Favourite album \n";
      cout<<"=============== \n \n";

      //feed first class values
      myFavouriteCD.setArtist(getNameOfArtist());
      myFavouriteCD.setTitle(getNameOfAlbum());
      myFavouriteCD.setNoOfTracks(getNoOfSongs());
      myFavouriteCD.setYear(getYearOfAlbum());
      
      cin.ignore(); //need to find out why we need this one!!!

      //get input for second class
      cout<<"\n \nWorst album \n";
      cout<<"=========== \n \n";

      //feed second class values
      myWorstCD.setArtist(getNameOfArtist());
      myWorstCD.setTitle(getNameOfAlbum());
      myWorstCD.setNoOfTracks(getNoOfSongs());
      myWorstCD.setYear(getYearOfAlbum());
      

      //print out values of first class
      cout<<"\n \n Favourite album";

      cout<<"\n Artist : "<<myFavouriteCD.getArtist();
      cout<<"\n Title : "<<myFavouriteCD.getTitle();
      cout<<"\n Number of tracks : "<<myFavouriteCD.getNoOfTracks();
      cout<<"\n Year : "<<myFavouriteCD.getYear();

      //print out values of second class
      cout<<"\n \n Worst album";

      cout<<"\n Artist : "<<myWorstCD.getArtist();
      cout<<"\n Title : "<<myWorstCD.getTitle();
      cout<<"\n Number of tracks : "<<myWorstCD.getNoOfTracks();
      cout<<"\n Year : "<<myWorstCD.getYear()<<"\n";

      char modifyChoice;
      
      cout<<"\n Do you wish to modify any of the details? (Y/N) : ";
      cin>>modifyChoice;

      if (modifyChoice == 'Y' || modifyChoice =='y')
      {
            modify();
      }
}



Do I need to add a class definition to this file and if so, how and where does it goes?

Thanks!Start Free Trial
[+][-]05.13.2006 at 11:14AM PDT, ID: 16674676

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2006 at 11:36AM PDT, ID: 16674793

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2006 at 11:52AM PDT, ID: 16674849

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: external, symbol, unresolved
Sign Up Now!
Solution Provided By: carl_tawn
Participating Experts: 4
Solution Grade: A
 
 
[+][-]05.13.2006 at 11:52AM PDT, ID: 16674852

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.14.2006 at 11:59PM PDT, ID: 16680247

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.07.2006 at 10:58AM PDT, ID: 16854663

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32