I\'ve been getting the follwoing errors when I run my makefile to complie everyt
ID: 3838860 • Letter: I
Question
I've been getting the follwoing errors when I run my makefile to complie everything.
If you can figure out what is causing this and how to fix it that would be great,
ERRORS:
g++ -c song.cpp
song.cpp: In constructor ‘Song::Song()’:
song.cpp:9:10: error: incompatible types in assignment of ‘int’ to ‘char [101]’
album = 0;
^
song.cpp: At global scope:
song.cpp:14:1: error: prototype for ‘Song::Song(char*, Genre, char*, double)’ does not match any in class ‘Song’
Song::Song(char tempTitle[], Genre tempGenre, char tempAlbum[], double tempDuration)
^~~~
In file included from song.cpp:2:0:
song.h:14:7: error: candidates are: constexpr Song::Song(const Song&)
class Song
^~~~
song.h:27:3: error: Song::Song(char*, Genre, int, double)
Song(char [], Genre, int, double);
^~~~
song.cpp:5:1: error: Song::Song()
Song::Song()
^~~~
song.cpp:40:6: error: prototype for ‘void Song::setAlbum(int)’ does not match any in class ‘Song’
void Song::setAlbum(int newAlbum)
^~~~
In file included from video.cpp:2:0:
song.h:33:8: error: candidate is: void Song::setAlbum(char*)
void setAlbum(char[]);
*****Here all my song.cpp and song.h files
//This is the implementation file for video.h (the Song class)
#include "song.h"
//default constructor
Song::Song()
{
strcpy(title, "No title");
genre = ILLEGAL;
album = 0;
duration =0;
}
//constructor with parameters
Song::Song(char tempTitle[], Genre tempGenre, char tempAlbum[], double tempDuration)
{
strcpy(title, tempTitle);
genre = tempGenre;
album = tempAlbum;
duration = tempDuration;
}
//destructor
Song::~Song()
{
//nothing to do now
}
//mutator functions
void Song::setTitle(char newTitle[])
{
strcpy(title, newTitle);
}
void Song::setGenre(Genre newGenre)
{
genre = newGenre;
}
void Song::setAlbum(int newAlbum)
{
album = newAlbum;
}
void Song::setDuration(double newDuration)
{
duration = newDuration;
}
//accessor functions
void Song::getTitle(char returnTitle[]) const
{
strcpy(returnTitle, title);
}
Genre Song::getGenre() const
{
return genre;
}
double Song::getDuration() const
{
return duration;
}
//prints to console
void Song::printSong()
{
char genreDesc[MAXCHAR];
printGenre(this->genre, genreDesc);
cout << title << ';' << genreDesc << ';' << album << ';' << duration << endl;
}
//prints to file
void Song::printSong(ofstream &outFile)
{
char genreDesc[MAXCHAR];
printGenre(this->genre, genreDesc);
outFile << title << ';' << genreDesc << ';' << album << ';' << duration << endl;
}
//This function assigns a Genre based on the letter and returns the Genre
Genre readGenre(char letter)
{
Genre tempGenre;
switch(tolower(letter))
{
case 'c':
tempGenre = static_cast(0);
break;
case 'h':
tempGenre = static_cast(1);
break;
case 'p':
tempGenre = static_cast(2);
break;
case 'j':
tempGenre = static_cast(3);
break;
default:
tempGenre = static_cast(4);
}
return tempGenre;
}
//This function populates the genreDesc based on the Genre
void printGenre(Genre tempGenre, char genreDesc[])
{
switch(tempGenre)
{
case 0:
strcpy(genreDesc, "COUNTRY");
break;
case 1:
strcpy(genreDesc, "HIPHOP");
break;
case 2:
strcpy(genreDesc, "POP");
break;
case 3:
strcpy(genreDesc, "JAZZ");
break;
case 4:
strcpy(genreDesc, "ILLEGAL");
break;
}
return;
}
song.h
#ifndef SONG_H
#define SONG_H
//Class object for video has title, genre, quantity, and rating
#include
#include
#include
using namespace std;
//constants
const int MAXCHAR = 101;
//enumerated data type for Genre
enum Genre {COUNTRY, HIPHOP, POP, JAZZ, ILLEGAL};
//data type for Video
class Song
{
private:
char title[MAXCHAR],
artist[MAXCHAR],
album[MAXCHAR];
Genre genre;
double duration;
public:
//constructors
//default constructor
Song();
//constructor with parameters
Song(char [], Genre, int, double);
//destructor
~Song();
//mutator functions
void setTitle(char []);
void setArtist(char[]);
void setAlbum(char[]);
void setGenre(Genre);
void setDuration(double);
//accessor functions
void getTitle(char []) const;
void getArtist(char[]) const;
void getAlbum(char[]) const;
Genre getGenre() const;
double getDuration() const;
//print video
void printSong();
void printSong(ofstream &);
};
Genre readGenre(char);
void printGenre(Genre, char []);
#endif
Explanation / Answer
Hi,
The prototype error happens whenever the function signature (in the source file) doesn't match the signature of the prototype (declaration in header):
In your case,
1. You have - Song::Song(char*, Genre, char*, double) in cpp but Song(char [], Genre, int, double) in header file so chage it to int, or i think in this case you have to change in the header method.
2. Similarly - void Song::setAlbum(int) in source and void setAlbum(char[]) in header. you have to change this too.
3. same problem as above cause the error of album=0 as it is int in one file and char[] in another.
After this changes, you should be good to go, let me know if you have any additional questions.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.