0
error: No such file or directory (classes)
newBeginning2020\main.cpp -o obj\Debug\main.o||No such file or directory| newBeginning2020\MyClass.cpp -o obj\Debug\MyClass.o||No such file or directory| So, when trying to compile the code I learned in the section classes (with sourcefile, etc.), I get this error above. I did pause my lection for a while, but I remember that there was a similar problem last time. Someone wrote about this (not uncommon) problem and explained that I basically had to edit the name of a file, like delete a "/", or "space". But I don't remember excactly where to edit, or what else to do. Maybe someone can help me with this one, as It ain't possible for me to compile anything right now.
4 Antworten
+ 1
First run MyClass.h header file, then MyClass.cpp, last main.cpp..
Make all in same current directory..
Here, looks fine but sry I can't check here, SoloLearn can't handle or include user defined header files...
0
Share your code that giving you trouble with info of where you running and how saving..
So then one can identify and report you where is error..
For previously answer similar question, you can use search to find out.. That help to avoid dublicates also...
0
Hey there. Thank you for answering. I searched via google but couldn't find it anymore unfortunately.
The code is not the problem for sure, but I will post it when I'm at my laptop later again.
0
So, I couldn't do it earlier but here is the code:
from main.cpp:
#include <iostream>
#include "MyClass.h"
using namespace std;
int main()
{
MyClass obj(42, 33);
}
----
from MyClass.cpp:
#include "MyClass.h"
#include <iostream>
using namespace std;
MyClass:MyClass(int a, int b)
:regVar(a), constVar(b)
{
cout<<regVar<<endl;
cout<<constVar<<endl;
}
----
from MyClass.h:
#ifndef MYCLASS_H
#define MYCLASS_H
class MyClass
{
public:
MyClass(int a, int b);
protected:
private:
int regVar;
const int constVar;
};
#endif // MYCLASS_H