User forums > Using Code::Blocks
new plugin idea
kidmosey:
--- Quote from: iw2nhl on July 13, 2006, 04:13:15 pm ---Sorry, but I don't understand the export you are talking about: can yoy explain it better, please?
(May be you are talking about a C++ feature that I don't know).
--- End quote ---
When I'm writing a new class, I include the implementation in the header file for speediness. This way I don't have to always switch between the .h and .cpp files to add members and methods, I just stay in the .h file until I am done with the testing phase for the class.
--- Code: ---class foo
{
...
void bar()
{
...
}
};
--- End code ---
What I am suggesting for an export feature is to right click on the method in the .h file and click "export/move implementation" to have it automatically copy the method to the .cpp file (maintaining the order of declarations in the class), and then just leave the declaration in the header file.
--- Code: ---foo.h:
class foo
{
...
void bar();
};
foo.cpp:
#include "foo.h"
...
void foo::bar()
{
...
}
--- End code ---
Does it make sense, now? Or am I the only person who works like this?
--- Quote from: iw2nhl on July 13, 2006, 04:13:15 pm ---For the reverse work: yes, I thought about the problems you mentioned and my solution was
1) when it is asked to add the declaration, show a little window with a combobox where you can choose between public, private, ecc.
2) add it to the first (or last) good line, then you can move it with your mouse (better a drag-drop than writing it yourself)
Do you agree?
--- End quote ---
Seems a bit complicated. Almost as much work as just copy/pasting the function definition.
iw2nhl:
--- Quote ---Does it make sense, now? Or am I the only person who works like this?
--- End quote ---
I don't know, I never worked like that, but may be other people do!
This could be done, but depends on how the parser works: it could be easy or not.
--- Quote ---Seems a bit complicated. Almost as much work as just copy/pasting the function definition.
--- End quote ---
I don't think so, you have to remove the 'Clas::' code and add a ';' -> this could be done automatically!
Raijinsetsu:
kidmosey: with gcc, you can use #pragma to define implementation and definition in the same file, and leave them there. This is not compatible with Visual Studio, and probably not compatible with other compilers either.
Example:
foo.h:
--- Code: ---#pragma interface
class foo
{
...
void bar()
{
...
};
};
--- End code ---
foo.c:
--- Code: ---#pragma implementation
#include "foo.h"
--- End code ---
Here's a link to the official gcc page for a full explanation: http://www.delorie.com/gnu/docs/gcc/gcc_96.html
In short: files with "#pragma interface" are only compiled when a "#pragma implementation" is found first. Otherwise, that file is just used as a definition.
--- Quote from: kidmosey on July 14, 2006, 01:26:26 am ---
--- Code: ---foo.h:
class foo
{
...
void bar();
};
foo.cpp:
#include "foo.h"
...
void foo::bar()
{
...
}
--- End code ---
Does it make sense, now? Or am I the only person who works like this?
--- End quote ---
kidmosey:
--- Quote from: Raijinsetsu on July 15, 2006, 03:31:00 pm ---kidmosey: with gcc, you can use #pragma to define implementation and definition in the same file, and leave them there. This is not compatible with Visual Studio, and probably not compatible with other compilers
--- End quote ---
Well, I believe if you leave all the methods defined inside the class (in the header), the compiler will only compile it once, anyway, so that isn't really a problem. I was just looking for an easier way to clean up the code and put declarations in the header and implementation in the source. It is poor practice to leave all your code in headers (I only do it during testing).
Also, I like to have all the code in the cpp file, otherwise I will have to recompile all the dependent objects anytime I change anything. I don't think the #pragma's can prevent that.
But I did read through that link and learned a few things, so thank you for that. I don't know that I'd ever use it, though, for the aforementioned reasons.
Navigation
[0] Message Index
[*] Previous page
Go to full version