Created a friend in class, gives 'no input files' error

129 Views Asked by At

I am an absolute beginner in C++ and trying to learn how to create a friend inside a class. I did everything exactly as the teacher did, but the compiler gives me two errors:

[Error] hj²k.cpp: No such file or directory
[Error] no input files

Where did I make a mistake? Could you please explain like I'm five?

class guts {
    public:
        guts() {gutsVar = 0};
    private:
        int gutsVar;
    friend void gutsfriend (guts &gutsObj);
    };

void gutsfriend (guts &gutsObj) {
        gutsObj.gutsVar = 99;
        cout << gutsObj.gutsVar << endl;
    }
int main () {
    guts obj2;
    gutsfriend (obj2);
}

I expect the output to be 99, but it doesn't even give me the blackboard. It says compilation terminated.

1

There are 1 best solutions below

0
Dondurma On

Apparently, it was because I was working on an old project. I closed the project, closed the compiler and opened it again, started a new source file. I copy-pasted the whole thing and it worked. Thanks everyone! Sorry for being silly.