• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Jak naprawić błąd : qualified-id in declaration before '(' token w C++ (obiektowo)?

Object Storage Arubacloud
0 głosów
1,438 wizyt
pytanie zadane 20 października 2019 w C i C++ przez Hyziu Nowicjusz (160 p.)

Cześć, piszę quiz w obiektowym C++ i trapią mnie dwa błędy (linie zaznaczone w kodzie), główkuję i nie mam pomysłu, co może działać źle. Pomożecie? Pliki załączam poniżej. Błędy występują w pliku Table_Of_Contents.cpp.

#include <iostream>
#include "Table_Of_Contents.h"

using namespace std;

int main()
{
    Question itself[5]; // Class's array.

    int sum = 0;

    for (int i = 0; i <= 4; i++)
    {
        itself[i].numberQ = i + 1;
        itself[i].load();
        itself[i].ask_question();
        itself[i].check_answer();
        sum += itself[i].points;
    }

    cout << "This is already the end! You scored " << sum << " points.";

    return 0;
}
// Table_Of_Contents.cpp

#include <iostream>
#include <fstream>
#include <stdlib.h> // The .h ending tells us that this library consists of useful functions and classes,
#include "Table_Of_Contents.h" // This line includes Table_Of_Contents.h file and expands stuff declared in it.

using namespace std;

void Question::load() // This sends compiler to the right class. It needs a guide, always.
 {
    fstream file;

    file.open("quiz.txt",ios::in);

    if(file.good() == false)
    {
        cout << "I am unable to read this file.";
        exit(0);
    }

    int line_as_int = (numberQ - 1) * 6 + 1; // This represent number of a line.
    int current_number = 1; // That is number of a current line.
    string line_as_string; // A variable representing the line itself.

    // Loop below is useful for expanding number of questions.

    while(getline(file,line_as_string)) // This loop reads needed lines from the file.
    {
        if(current_number == line_as_int) content = line_as_string;
        if(current_number == line_as_int + 1) a = line_as_string;
        if(current_number == line_as_int + 2) b = line_as_string;
        if(current_number == line_as_int + 3) c = line_as_string;
        if(current_number == line_as_int + 4) d = line_as_string;
        if(current_number == line_as_int + 5) rightAnswer = line_as_string;

        current_number++;
    }

 void Question::ask_question() // Error: qualified-id in declaration before '(' token.
 {
     cout << content << endl;
     cout << a << endl;
     cout << b << endl;
     cout << c << endl;
     cout << d << endl;
     cout << endl;
     cout << "Your answer is... "; cin >> answer;
 }

 void Question::check_answer() // Error: qualified-id in declaration before '(' token.
 {
     if (answer == right_answer)
     {
        points = 1;
     }

     else
     {
        points = 0;
     }
 }

    file.close();
 } // Error: expected '}' at end of input.
// Table_Of_Contens.h

#include <iostream>

using namespace std;

class Question
{
    public:

    string content;
    string a, b, c, d;
    int numberQ;
    string rightAnswer;
    string answer;
    int points;

    // int points = 0;
    // Such operation is invalid when it comes to the .h file, it pops up an error.

    void load(); // This method will load information such as content and answers from the text file.
                 // This function's body is located in .cpp file.

    void ask_question();
    void check_answer();

};

// This file is just a table of stuff in .cpp file, but its existence makes it easier to look at the application.
// Here there are only headers.

 

1 odpowiedź

0 głosów
odpowiedź 20 października 2019 przez tkz Nałogowiec (42,000 p.)
void Question::check_answer() // Error: qualified-id in declaration before '(' token.
 {
     if (answer == right_answer)
     {
        points = 1;
     }
     else
     {
        points = 0;
     }
 } //za duzo o jeden
 
    file.close();
 } // Error: expected '}' at end of input.

 

Podobne pytania

0 głosów
1 odpowiedź 99 wizyt
pytanie zadane 26 października 2023 w C i C++ przez Piotrek2713 Mądrala (5,400 p.)
0 głosów
1 odpowiedź 1,360 wizyt

92,594 zapytań

141,443 odpowiedzi

319,714 komentarzy

61,980 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...