Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;:成员'的错误请求;Foo';在';f';,属于非类类型';Foo*';_C++_Oop_Compiler Errors - Fatal编程技术网

C++ C++;:成员'的错误请求;Foo';在';f';,属于非类类型';Foo*';

C++ C++;:成员'的错误请求;Foo';在';f';,属于非类类型';Foo*';,c++,oop,compiler-errors,C++,Oop,Compiler Errors,我知道以前有人问过这个问题。我已经尝试实现了这些答案,但仍然遇到了这个错误。如果有人有任何建议,我们将不胜感激。下面是主文件、头文件和源文件。如果您需要任何其他信息,请告诉我。谢谢 main.cpp /* * File: main.cpp * Author: agoodkind * * Reads in a .list file from IMDB * Prompts user for Actor or Movie lookup * Iterates through file

我知道以前有人问过这个问题。我已经尝试实现了这些答案,但仍然遇到了这个错误。如果有人有任何建议,我们将不胜感激。下面是主文件、头文件和源文件。如果您需要任何其他信息,请告诉我。谢谢

main.cpp

/* 
 * File:   main.cpp
 * Author: agoodkind
 *
 * Reads in a .list file from IMDB
 * Prompts user for Actor or Movie lookup
 * Iterates through file
 * Returns results of query
 * 
 */

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>

#include "ActorResume.h"

using namespace std;


// function prototypes
void printmenu(void);
void createMovieList(fstream &infile);
void movieCastLookup(void);
void costarLookup(ActorResume &, fstream &infile);

int main() {    

    char choice;                //user menu selection
    bool not_done = true;       // loop control flag

    // create input file stream
    fstream infile;
    // CHANGE BACK TO NON-TEST!! 
    infile.open("/Users/agoodkind/Documents/CUNY/Analysis_and_Design/Assignments/Assignment1/actorsTEST.2010.list", ios::in);


    do {
        printmenu();
        cin >> choice;
        switch(choice)
        {
            case 'q':
            case 'Q':
                infile.close();
                not_done = false;
                break;
            case 'a':
            case 'A':
                createMovieList(infile);
                break;
            case 'm':
            case 'M':
                movieCastLookup();
                break;
            default:
                cout << endl << "Error: '" << choice << "' is an invalid selection -  try again" << endl;
                break;
        } //close switch

    } // close do() loop

    // exit program
    while (not_done);
    return 0;
} // close main()

/* Function printmenu()
 * Input:
 *  none
 * Process:
 *  Prints the menu of query choices
 * Output:
 *  Prints the menu of query choices
 */
void printmenu(void) {
    cout << endl << endl;
    cout << "Select one of the following options:" << endl;
    cout << "\t****************************" << endl;
    cout << "\t    List of Queries         " << endl;
    cout << "\t****************************" << endl;
    cout << "\t     A -- Look Up Actors' Costars" << endl;
    cout << "\t     M -- Movie Cast List" << endl;
    cout << "\t     Q -- Quit" << endl;
    cout << endl << "\tEnter your selection: ";
    return;    
}

/* Function costarLookup()
 * Input:
 *      Actor name
 * Process:
 *      Looks up all actors also in actor's movieList
 * Output:
 *      Prints list of costars
 */
void createMovieList(fstream &infile) {

    string actorName; // actor's name to be queried

    cout << endl << "Enter Actor Name: ";
    cin >> actorName;

    ActorResume *ar = new ActorResume(actorName);

    // add movie list to ActorCostars ADT created above
    // string for readline()
    string line;

    if (infile.is_open()) { //error checking to ensure file is open
        infile.seekg(0, ios::beg); // to be safe, reset get() to beginning of file
        while (infile.good()) { //error checking to ensure file is being read AND not end-of-file

            bool actor_found = false; // checks if actor name has been found
            getline(infile,line);

            if (line == actorName) {
                actor_found = true;
            }

            // add movies to actor's movieList
            while (actor_found && line[0] == '\t') {
                ar.addMovie(line);
            } 
        }
    }

    costarLookup(*ar, infile);
    delete ar;

} // close costarLookup()


void costarLookup(ActorResume actRes, fstream &infile) {

    // string for readline()
    string line;

    // vector to store costar names
    vector<string> costars;

    if (infile.is_open()) {             // error checking to ensure file is open

        infile.seekg(0, ios::beg);      // reset get() to beginning of file
        while (infile.good()) {         // error checking to ensure file is being read AND not end-of-file

            // while looping through file, store each actor's name
            string actorName;

            getline(infile,line);

            // check if first character is an alphanumeric character
            if (line[0] != '\t' && line[0] != NULL) {
                actorName = line;
            }

            // add actors name to list of costars
            if (actRes.movieInList(line)) {
                costars.push_back(actorName);
            }
        }
    }
    if (costars.size() == 0) {
        cout << "No costars found";
    }
    else if (costars.size() > 0) {
        cout << "Costars of " << actRes.getActorName() << ": " << endl;
        for (int i = 0; i < costars.size(); i++) {
            cout << "* " << costars[i];
        }
    }
}
“f”中成员“Foo”的错误请求,该成员属于非类类型“Foo*”

这个错误告诉你你需要知道的一切

ActorResume *ar = new ActorResume(actorName);
ar
是指向
ActorResume
对象的指针,而不是
ActorResume
对象本身。所以

ar.addMovie(line);
应该是

ar->addMovie(line);
您可以使用
->
操作符解除指针的限制并访问它所引用的对象的成员,而不是点操作符。指针没有成员

“f”中成员“Foo”的错误请求,该成员属于非类类型“Foo*”

这个错误告诉你你需要知道的一切

ActorResume *ar = new ActorResume(actorName);
ar
是指向
ActorResume
对象的指针,而不是
ActorResume
对象本身。所以

ar.addMovie(line);
应该是

ar->addMovie(line);

您可以使用
->
操作符解除指针的限制并访问它所引用的对象的成员,而不是点操作符。指针没有成员。

使用名称空间std
不是任何使用您的标题的人都应该处理的问题。注释已被删除,但是是的,您应该提供我们可以使用的最小片段。这里有一个可以完美复制错误的示例(GCC4.7.1非常贴切地告诉您需要做什么来修复错误),只有8行。与您提供的几十行代码相比,您会注意到这是多么容易提供帮助。@chris-我肯定知道这一点,但在我的delerium中,我不确定我的代码中是否隐藏着鹰眼观察家会发现的其他东西。谢谢你<代码>使用名称空间std不是任何使用您的标题的人都应该处理的问题。注释已被删除,但是是的,您应该提供我们可以使用的最小片段。这里有一个可以完美复制错误的示例(GCC4.7.1非常贴切地告诉您需要做什么来修复错误),只有8行。与您提供的几十行代码相比,您会注意到这是多么容易提供帮助。@chris-我肯定知道这一点,但在我的delerium中,我不确定我的代码中是否隐藏着鹰眼观察家会发现的其他东西。谢谢你!必须强调的是,指向
ActorResume
的指针与
ActorResume
的指针不同。他们是两种完全不同的类型,其中一种是有成员的班级。非常感谢!我学C++已经有一段时间了,大脑完全消失了。我几乎不是最好的,所以经常发生这种事强调指向
ActorResume
的指针不同于
ActorResume
,这一点非常重要。他们是两种完全不同的类型,其中一种是有成员的班级。非常感谢!我学C++已经有一段时间了,大脑完全消失了。我几乎不是最好的,所以经常发生这种事D