Reputation: 23
I'm making a little shell that can just do random stuff. Bt whenever i compile i receive the error 'Shell' has not been declared
I declared the class shell and the object i n main.cpp, i've looked for a while and nothing. I'm new to oop so this may be pretty stupid but i've done wha to know
I'm using 3 files
main.cpp:
#include <iostream>
#include "shell/shell.cpp"
int main ()
{
Shell shl;
while (!shl.exitTime())
{
std::cin.ignore();
shl.putIn(std::getline(std::cin));
}
}
/shell/shell.cpp:
#include <vector>
#include "shell.h"
class Shell {
private:
std::string in;
bool exitBool;
public:
// Functions
void clear();
void print(std::string inp);
void println(std::string inp);
void putIn(std::string inp);
std::string input();
bool exitTime();
Shell()
{
exitBool = false;
}
};
and /shell/shell.h:
#include <vector>
void Shell::print(std::string inp)
{
std::cout << inp;
}
void Shell::println(std::string inp)
{
std::cout << inp << std::endl;
}
void Shell::putIn(std::string inp)
{
inp = in;
}
std::string Shell::input()
{
return in;
}
bool exitTime()
{
return exitBool;
}
Upvotes: 0
Views: 804
Reputation: 75062
You should
.cpp
files..h
files..h
files.You actually did
.h
files..cpp
files..cpp
files.Try this:
main.cpp:
#include <iostream>
#include "shell/shell.h"
int main ()
{
Shell shl;
while (!shl.exitTime())
{
std::cin.ignore();
shl.putIn(std::getline(std::cin));
}
}
/shell/shell.cpp:
#include <vector>
#include "shell.h"
void Shell::print(std::string inp)
{
std::cout << inp;
}
void Shell::println(std::string inp)
{
std::cout << inp << std::endl;
}
void Shell::putIn(std::string inp)
{
inp = in;
}
std::string Shell::input()
{
return in;
}
bool exitTime()
{
return exitBool;
}
and /shell/shell.h:
#include <vector>
#include <string>
class Shell {
private:
std::string in;
bool exitBool;
public:
// Functions
void clear();
void print(std::string inp);
void println(std::string inp);
void putIn(std::string inp);
std::string input();
bool exitTime();
Shell()
{
exitBool = false;
}
};
Upvotes: 1