Problem with "not declared in this scope" error

Posted by lego69 on Stack Overflow See other posts from Stack Overflow or by lego69
Published on 2010-06-14T17:18:38Z Indexed on 2010/06/14 17:32 UTC
Read the original article Hit count: 130

Filed under:
|

I've got:

error a1 was not declared in this scope

Can somebody please explain why this code causes that?

quiz.h

#ifndef QUIZ_H_
#define QUIZ_H_

    #include "quiz.cpp"


    class A {
    private:
        int player;
    public:
        A(int initPlayer);
        ~A();
        void foo();
    };


    #endif /* QUIZ_H_ */

quiz.cpp

#include "quiz.h"
#include <iostream>
using std::cout;
using std::endl;

A::A(int initPlayer = 0){
    player = initPlayer;
}

A::~A(){

}

void A::foo(){
    cout << player;
}

main function

#include "quiz.h"
int main()
{
        quiz(7);
        return 0;
}

quiz function

#include "quiz.h"

void quiz(int i)
{
        A a1(i);
        a1.foo();
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about programming