Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: va!n on May 28, 2015
-
Atm i write all the code of my test projects in just one cpp (the main cpp) file, which really suxx. I would like to have the main.cpp (creating windows/GUI and handling messages)... and have seperate .cpp files for all the FilterEffects, another .cpp for all the AdjustmentFunctions and so on.
How to use a buffer (storing image datas as 1D array) and access this buffer from FilterEffects.cpp and from AdjustFunctions.cpp?
I know this may be some very basic stuff but i would be really glad to get some teaching / help, how to realize this. 8)
Atm i am using this way...
static long bufferColors[360 * 256];
-
cpp files are often paired with a .h file of the same name. In that .h file you declare stuff you want to share and then include it into other .h or .cpp files.
in a new file data.h:
static long bufferColors[360 * 256];
Then add this to every file where you will use it
#include "data.h"
-
@spitfire:
Thanks a lot for your very helpfull answer and great explation/example !! :cheers:
I mangaed to get it work :updance:
K++
-
What I found quite useful is when using headers is to use a header guard, as often I would get compile errors saying that variables and functions had already been declared.
All you need do is surround your code with:
#ifndef _NAME_OF_HEADER_H_
#define _NAME_OF_HEADER_H_
#endif
btw, the _H_ is optional.
hope it helps.
-Clyde.
-
What I found quite useful is when using headers is to use a header guard, as often I would get compile errors saying that variables and functions had already been declared.
All you need do is surround your code with:
#ifndef _NAME_OF_HEADER_H_
#define _NAME_OF_HEADER_H_
#endif
btw, the _H_ is optional.
hope it helps.
-Clyde.
Optional you can use #pragma once which should be compiled by the most (modern) Compilers.
-
in a new file data.h:
static long bufferColors[360 * 256];
Then add this to every file where you will use it
#include "data.h"
This way every cpp-file which includes data.h will create its own buffer.
But I guess what Vain asked for is a single shared buffered like this:
// mybuffer.cpp
long buffer[360*256];
// mybuffer.h
#pragma once
extern long buffer[320*256];
// mycode1.cpp
#include "mybuffer.h"
// mycode2.cpp
#include "mybuffer.h"
This way mycode1 & mycode2 will work on the same "buffer" from mybuffer.cpp.
-
Thanks for the reply.
hellfire is right, his example is exactly what i am looking for.
:goodpost: