Originally Posted by
Elysia
Yes, but that's not the point.
The point is that the return type of
Code:
const XTrackInfo GetTracks() const { return m_TrackInfo;}
does not match the actual type of m_TrackInfo.
It is a vector
Theres is an update:
Code:
#include <iostream>
#include <vector>
#include <string>
// You may not modify XTrackInfo
class XTrackInfo
{
std::string m_TrackName;
int m_Length;
public:
XTrackInfo() {}
XTrackInfo(std::string TrackName, int Length):
m_TrackName(std::move(TrackName)),
m_Length(Length)
{}
void SetTrackName(std::string TrackName) { m_TrackName = std::move(TrackName); }
void SetTrackLength(int Length) { m_Length = Length; }
const std::string& GetTrackName() const { return m_TrackName; }
int GetTrackLength() const { return m_Length; }
};
class XMusicCd
{
private:
// You may not modify these member variables
std::string m_Author;
std::vector<XTrackInfo> m_TrackInfo;
public:
// You may not modify these member functions
XMusicCd() {}
XMusicCd(std::string Author, std::vector<XTrackInfo> Tracks):
m_Author(std::move(Author)),
m_TrackInfo(std::move(Tracks))
{}
void SetAuthor(std::string Author) { m_Author = std::move(Author); }
const std::string& GetAuthor() const { return m_Author; }
const std::vector<XTrackInfo> GetTracks() const { return m_TrackInfo;}
int GetLength() const; // Left incomplete on purpose; you will implement it later
void AddTrack(XTrackInfo NewTrack){
//m_TrackInfo.emplace_back(NewTrack.GetTrackName(),NewTrack.GetTrackLength());
m_TrackInfo.emplace_back(std::move(NewTrack));
}
// Add additional functions to this class as necessary to make it compile.
};
void PrintCdContents(const XMusicCd& Cd)
{
// Implement this function such that it compiles
// Also, to be explicit, you may not add any tracks to the CD in here. That is not the purpose of this function. You may also not change the signature of the function.
// You shall specifically not modify the CD object by calling any setters.
//Cd.
std::cout << "Author : " << Cd.GetAuthor() << "\n";
std::cout << "\n" << std::endl;
std::cout << "Track Info" << std::endl;
Cd.GetTracks();
// for (auto it = NewTrack.begin(), end = NewTrack.end(); it != end; ++it)
// {
// std::cout << *it << " ";
// }
}
int main()
{
// You may not change this function
XMusicCd MyCd;
MyCd.SetAuthor("Hello World");
MyCd.AddTrack(XTrackInfo("This is a test", 100));
MyCd.AddTrack(XTrackInfo("This is a test 2", 200));
PrintCdContents(MyCd);
}
At this moment I don't know which is the best: Create operators in order to use iterators or simply try to print the Tracks content .
I think the best pratice is the the first one.