Hi there,

I'm trying to create a demonstration of a modified copy constructor. As can be seen from the code below, I've created a class called Track and defined a copy constructor such that a new object of type "Track" can be defined with the same track artist and album name, but increment the track number by 1. It compiles fine, but when I try to run it in MS VC++, I get two link errors:
"error LNK2001: unresolved external symbol", and
"fatal error LNK1120: 1 unresolved externals".

If anybody can tell me what I'm doing wrong, it would be much appreciated!

#include<iostream>
#include<string>

using namespace std;


class Track
{
      
public:
       
    string artist;   
	string album;
	int trackNumber;

    Track(string artist, string album, int trackNumber);
    Track(const Track &sourceTrack);
    
    virtual void display();
};

Track::Track(const Track &sourceTrack):		//Copy constructor
    artist(sourceTrack.artist),
    album(sourceTrack.album),
    trackNumber(sourceTrack.trackNumber + 1)
{
}

void Track::display()
{
    cout << "Artist: " << artist << endl
      << "Album: " << album << endl
    << "Track Number: " << trackNumber << endl;
}

int main()
{
    Track a = Track("TOOL","Third Eye",13); 
    Track b(a);
    
    a.display();
    b.display();  //Should display a new object "b" of type Track 
				  //with the same artist and title as object "a", 
				  //except increment trackNumber by 1 

   	system("Pause");
	return EXIT_SUCCESS;
}

Recommended Answers

All 2 Replies

So where did you code the function in line 16 ?

Yep, I just realised I left something out. I had to include two additional constructors to satisfy line 16:

Track::Track(string anArtist, string anAlbum, int aTrackNumber):
	artist(anArtist), album(anAlbum),
	trackNumber(aTrackNumber) {}
	
Track::Track(string anAlbum, int aTrackNumber) :
	album(anAlbum), trackNumber(aTrackNumber),
	artist("Not Defined") {}

It works now! :)
Thanks Ancient Dragon!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.