unresolved external symbol

Hi

I've just started learning C++ although I'm not new to programming so I've just started trying to teach myself the basics. I've written an incredibly simple program to input various details about a CD, store these in a class and output them again. The program compiles without any errors but when I go to build, I get the following message....

CompactDiscs.obj : error LNK2001: unresolved external symbol "public: __thiscall CD::CD(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::all
ocator<char> >,int,int)" (??0CD@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0HH@Z)
Debug/Assignment7.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

My code is as follows....

#include <iostream>
#include <string>

using namespace std;

class CD
{
      public:
            CD();    // Default Constructor
            CD(string artist, string title, int noOfTracks, int year);

            void setArtist(string newArtist)
            {
                  artist = newArtist;
            }
            string getArtist()
            {
                  return artist;
            }
            
            void setTitle(string newTitle)
            {
                  title = newTitle;
            }
            string getTitle()
            {
                  return title;
            }

            void setNoOfTracks(int newNoOfTracks)
            {
                  noOfTracks = newNoOfTracks;
            }
            int getNoOfTracks()
            {
                  return noOfTracks;
            }
            
            void setYear(int newYear)
            {
                  year = newYear;
            }
            int getYear()
            {
                  return year;
            }

      private:
            string artist;
            string title;
            int noOfTracks;
            int year;
};

void main()
{
      //define input holders
      string inputArtist;
      string inputTitle;
      int inputNoOfTracks;
      int inputYear;

      //get input for first class
      cout<<"Favourite album \n \n";

      cout<<"\n Please enter name of artist: ";
      cin>>inputArtist;

      cout<<"\n Please enter title of album : ";
      cin>>inputTitle;

      cout<<"\n Please enter number of tracks : ";
      cin>>inputNoOfTracks;

      cout<<"\n Please enter year of album : ";
      cin>>inputYear;

      //create class with values
      CD myFavouriteCD(inputArtist, inputTitle, inputNoOfTracks, inputYear);

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

      cout<<"\n Please enter name of artist: ";
      cin>>inputArtist;

      cout<<"\n Please enter title of album : ";
      cin>>inputTitle;

      cout<<"\n Please enter number of tracks : ";
      cin>>inputNoOfTracks;

      cout<<"\n Please enter year of album : ";
      cin>>inputYear;

      //create class with values
      CD myWorstCD(inputArtist, inputTitle, inputNoOfTracks, inputYear);

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

      cout<<"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<<"Artist : "<<myWorstCD.getArtist();
      cout<<"\n Title : "<<myWorstCD.getTitle();
      cout<<"\n Number of tracks : "<<myWorstCD.getNoOfTracks();
      cout<<"\n Year : "<<myWorstCD.getYear();
}


What am I doing wrong?
UzibatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:
Hi, where is your constructor definition ? Put this outside the class:

CD::CD(string artist, string title, int noOfTracks, int year)
{
    this->artist = artist;
    this->title = title;
    this->noOfTracks = noOfTracks;
    this->year = year;    
}


---
Harish
ikeworkCommented:
hi

the constructor implementation for CD is missing:

replace:

CD(string artist, string title, int noOfTracks, int year);

with:

CD(string a, string t, int n, int y) : artist(a), title(t), noOfTracks(n), year(y) {}


be sure to usedifferent names for passed parameters and member-variables, i changed them ...


good luck :)
ike

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UzibatAuthor Commented:
Thanks a bunch. I'm literally trying to cobble together programs using a variety of websites' tutorials and haven't come across one that explains exactly what I need to know. Now I know how to make a proper constructor, life should be a lot easier!

Thanks for the prompt answers! :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.