1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
|
#include <string>
#include<iostream>
using namespace std;
#include "CPlaylist.h"
#include "CTitle.h"
CPlaylist::CPlaylist(int initialSize ){
if (initialSize <= 0){
initialSize = 5;
}
m_arraySize = initialSize;
m_titles = (CTitle**)malloc(m_arraySize * sizeof(CTitle*));
if (m_titles == NULL){
throw "Failed to allocate memory.";
}
}
CPlaylist::~CPlaylist(){
free(m_titles);
}
void CPlaylist::add(CTitle* title){
if (m_nextFree + 1 >= m_arraySize){
m_titles = realloc(m_titles, m_arraySize + 5);
if (m_titles == NULL){
throw "Failed to allocate memory";
}
m_arraySize += 5;
}
*(m_titles+m_nextFree++) = title;
}
}
int const CPlaylist::totalPlayTime(){
for( int i = 0; i<m_arraySize; i++){
int temp_mtitles;
temp_mtitles = temp_mtitles[i] +m_titles;
CTitle* temp = new CTitle(temp_mtitles);
return* temp;
}
}
|