For a project, our professor has provided us with one .cpp file and three .h files containing Class definitions. The goal of the project is to construct the implementation .cpp files for these Classes.
I'm aware that using namespace std; is bad practice and should be avoided at all costs, but the teacher insists on three important points in the completion of the project:
- You must not modify any of the provided files. "Not a single character". (60% reduction in marks)
- It fails to build in Visual Studio 2017. (60% reduction in marks)
- It crashes during normal operation. (60% reduction in marks)
My problem is that I'm receiving some errors pertaining to his definition of a forward_list<> in one of the Classes. These errors mean nothing to me... I've been scratching my head for the last few hours, while attempting to remedy these errors:
1>Animation.cpp
1>AnimationManager.cpp
1>c:\users\ali-g\desktop\cst8219\assignment2\assignment2\animation.h(7): error C2143: syntax error: missing ';' before '<'
1>c:\users\ali-g\desktop\cst8219\assignment2\assignment2\animation.h(7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ali-g\desktop\cst8219\assignment2\assignment2\animation.h(7): error C2238: unexpected token(s) preceding ';'
1>Ass2.cpp
1>Generating Code...
1>Done building project "Assignment2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the .h file he provided, containing the Animation class definition:
//Animation.h
#pragma once
class Animation
{
string animationName;
forward_list<Frame> frames;
public:
Animation(string name) :animationName(name) {}
~Animation() {}
void EditFrame();
void DeleteFrame();
friend istream& operator>>(istream&, Animation&);// Add a Frame as in cin >> A;
friend ostream& operator<<(ostream&, Animation&);// output the Frames as in cout << A;
};
Here is my implementation .cpp file from Animation Class:
//Animation.cpp
#include <iostream>
#include <string>
#include <forward_list>
using namespace std;
#include "Frame.h"
#include "Animation.h"
void Animation::EditFrame() {
}
void Animation::DeleteFrame() {
}
istream& operator>> (istream& in, Animation& animation) {
return in;
}
ostream& operator<< (ostream& out, Animation& animation) {
return out;
}
The .h file he provided containing the definition for AnimationManager Class:
// AnimationManager.h
#pragma once
class AnimationManager
{
string managerName;
vector<Animation> animations;
public:
AnimationManager(string name) :managerName(name) {}
~AnimationManager() {}
void EditAnimation();
void DeleteAnimation();
friend istream& operator>>(istream&, AnimationManager&);// add an Animation
friend ostream& operator<<(ostream&, AnimationManager&);// output the Animations
};
And here is my implementation file for AnimationManager Class:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include "Frame.h"
#include "Animation.h"
#include "AnimationManager.h"
void AnimationManager::EditAnimation() {
}
void AnimationManager::DeleteAnimation() {
}
istream & operator>>(istream &in, AnimationManager &manager){
string name;
cout << "Please enter Animation Name: ";
cin >> name;
//resize vector array to accommodate a new Animation
manager.animations.resize(manager.animations.size() + 1);
manager.animations.push_back(Animation(name));
}
ostream & operator<<(ostream &out, AnimationManager &manager){
}
I'll also include the .h & .cpp file for the other included header file (Frame.h), as it may help you find my (most likely stupid) mistake.
"Frame.h":
// Frame.h
#pragma once
class Frame{
char* frameName;
double duration;
public:
Frame(char*, double);
Frame(const Frame&);
~Frame();
Frame& operator=(const Frame&);
friend ostream& operator<<(ostream&, Frame&);
};
"Frame.cpp":
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include "Frame.h"
Frame::Frame(char* name, double dur) {
//Set frame name
frameName = new char[strlen(name) + 1];
strcpy(this->frameName, name);
//set duration
duration = dur;
}
Frame::Frame(const Frame& frame) {
//copy name from passed frame
frameName = new char[strlen(frame.frameName) + 1];
strcpy(frameName, frame.frameName);
//copy duration
duration = frame.duration;
}
Frame::~Frame() {
//free the space allocated for frameName
if (frameName != nullptr) {
delete[] frameName;
}
}
Frame& Frame::operator= (const Frame& frame) {
//create new Frame using given frame information
Frame copyFrame = Frame(frame.frameName, frame.duration);
//return reference to new frame.
return copyFrame;
}
ostream& operator<< (ostream& out, Frame& frame) {
//add frameName and duration to ostream.
out << "\tframeName - " << frame.frameName << "; ";
out << "duration - " << frame.duration << endl;
//return ostream
return out;
}
I would greatly appreciate any help in solving this problem. Thanks in advance!