R
Roman Töngi
I don't yet understand how to divide a C++ project
into header and implementation files. The following won't
compile:
// Apple.cpp
#include <iostream>
#include "random.h"
using namespace std;
int main()
{
cout << random();
return 0;
}
// random.h
double random();
// random.cpp
#include <cstdlib>
#include <ctime>
// is it necessary to include random.h?
#include "random.h"
double random()
{
double rnd;
std::srand(static_cast<unsigned>(std::time(NULL)));
rnd = static_cast<double>(std::rand()) / RAND_MAX;
return rnd;
}
There is an error message something like this: searching error for directive
for the precompiled header file.
into header and implementation files. The following won't
compile:
// Apple.cpp
#include <iostream>
#include "random.h"
using namespace std;
int main()
{
cout << random();
return 0;
}
// random.h
double random();
// random.cpp
#include <cstdlib>
#include <ctime>
// is it necessary to include random.h?
#include "random.h"
double random()
{
double rnd;
std::srand(static_cast<unsigned>(std::time(NULL)));
rnd = static_cast<double>(std::rand()) / RAND_MAX;
return rnd;
}
There is an error message something like this: searching error for directive
for the precompiled header file.