D
Daniel Pfeiffer
Hi,
for a while now I've been looking for a smart C++ class splitter that allows
programming in one file as in Java. This would eliminate the need of
repeating all declarations differently in the definition.
I guess the reason I can't find anything is that traditional make would be
recompiling tons of stuff all the time. But modern alternatives like makepp
would notice that the updated x.hh is the same as before, so there's no
drawback any more. Essentially I want something like:
/********** x.cpp: **********/
#include <string>
using namespace std;
class X
{
static int i = 0; // illegal, some IDEs might barf :-(
public:
inline void f(string s) { ... }
// bla bla
void g(string s) { ... } // not to be inline!
};
This would get split into the following two files for the compiler to see:
/********** x.hh: **********/
#ifndef _X_CPP_
#define _X_CPP_
#line 1 "x.cpp"
#include <string>
class X
{
static int i;
public:
inline void f(std::string s) { ... }
void g(std::string);
};
#endif
/********** x.cc: **********/
#include "x.hh"
#line 2 "x.cpp"
using namespace std;
#line 5
int X::i = 0;
#line 9
void X::g(string s) { ... }
The other reason is probably that with namespaces, nested classes, enums,
typedefs and whatnot, this rewriting is a rather tough one. But that's
because the whole topic is a mess in C++. I guess this causes numerous
compilations attempts, especially for beginners, until you get it right. All
the more reason to do this!
Any solutions or thoughts?
best regards - Daniel
for a while now I've been looking for a smart C++ class splitter that allows
programming in one file as in Java. This would eliminate the need of
repeating all declarations differently in the definition.
I guess the reason I can't find anything is that traditional make would be
recompiling tons of stuff all the time. But modern alternatives like makepp
would notice that the updated x.hh is the same as before, so there's no
drawback any more. Essentially I want something like:
/********** x.cpp: **********/
#include <string>
using namespace std;
class X
{
static int i = 0; // illegal, some IDEs might barf :-(
public:
inline void f(string s) { ... }
// bla bla
void g(string s) { ... } // not to be inline!
};
This would get split into the following two files for the compiler to see:
/********** x.hh: **********/
#ifndef _X_CPP_
#define _X_CPP_
#line 1 "x.cpp"
#include <string>
class X
{
static int i;
public:
inline void f(std::string s) { ... }
void g(std::string);
};
#endif
/********** x.cc: **********/
#include "x.hh"
#line 2 "x.cpp"
using namespace std;
#line 5
int X::i = 0;
#line 9
void X::g(string s) { ... }
The other reason is probably that with namespaces, nested classes, enums,
typedefs and whatnot, this rewriting is a rather tough one. But that's
because the whole topic is a mess in C++. I guess this causes numerous
compilations attempts, especially for beginners, until you get it right. All
the more reason to do this!
Any solutions or thoughts?
best regards - Daniel