#include <iostream>
#include <string>
using namespace std;

class Movie {
        string director, title, genre, cast, rating, release;
        int length;
                cout<<"constructor w/ no parameters called"<<endl;
        Movie(string d, string t, string g, int l, string c, string r, string re){
        string getDirector();                
        string getTitle();
        string getGenre();
        int getLength();
        string getCast();
        string getRating();
        string getRelease();
        void setDirector(string d);
        void setTitle(string t);
        void setGenre(string g);
        void setLength(int l);
        void setRating(string r);
        void setRelease(string re);
void Movie::setDirector(string d){
void Movie::setTitle(string t){
void Movie::setGenre(string g){
void Movie::setLength(int l){
void Movie::setRating(string r){
void Movie::setRelease(string re){
string Movie::getDirector(){
        return director;}
string Movie::getTitle(){
        return title;}
string Movie::getGenre(){
        return genre;}
int Movie::getLength(){
        return length;}
string Movie::getCast(){
        return cast;}
string Movie::getRating(){
        return rating;}
string Movie::getRelease(){
        return release;}
int main(){
        cout<<"My Movies are: The Departed, The Matrix, Cloverfield"<<endl;
        Movie a(Scorcese, the Departed, Drama, 151, Leonardo diCaprio, 5 Stars, 2006);
        Movie b(Wachowski Brothers, The Matrix, SciFi, 136, Keanu Reeves, 4.5 Stars, 1999);
        Movie c(Reeves, Cloverfield, SciFi, 84, TJ Miller, 4.5 Stars, 2007);
        return 0;}

I am trying to create a class movie. When i enter in the Movie a,b,etc. it gives me the error undeclared identifier. I don't understand this error i was under the impression that by syntaxing it in that way it would call upon the constructor and enter it as that. any help?

Recommended Answers

All 5 Replies

also i know all my definitions are outside of the class it was a requirement

An identifier and a string are different because a string is surrounded by double-quotes.

Movie a(
  "the Departed",
  "Leonardo diCaprio",
  "5 Stars",

Formatted for readability...

Have fun!

thank you very much i knew i was just missing something...its been 2 years since i have had c++

string Movie::show(){
	string s1;
	return s1;}
int Movie::showtime(){
	int time1;
	return time1;}
int Movie::showtimem(){
	int time2;
	return time2;}

is it possible to bring these three into one operation...i guess my real question is "is it possible to return more than one value and if yes then more than one value of more than one type?"

Yes. The easiest way would be to use reference parameters.

void Movie::getstuff( std::string &name, int &hours, int &minutes ) {
  name    = getTitle();
  hours   = getLength() /60;
  minutes = getLength() %60;

Then you would call it like

std::string title;
int hour, min;
a.getstuff( title, hour, min );
std::cout << '"' << title << "\" has a runtime of "
  << hour << ':' << min << std::endl;

That said, the better way is to keep it separate like you have it.

std::cout << '"' << a.getTitle() << "\" has a runtime of "
  << a.showtime() << ':' << a.showtimem() << std::endl;

Good luck.

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.