Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Usage of images in different .h and .cpp files
Usage of images in different .h and .cpp files [message #27600] Sun, 25 July 2010 13:52 Go to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Hi,

I have the following question: how to use images contained in a single .iml file in different classes, each one defined by its corresponding .h and .cpp file?

Cheers,

Javier
Re: Usage of images in different .h and .cpp files [message #27602 is a reply to message #27600] Sun, 25 July 2010 15:23 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

281264 wrote on Sun, 25 July 2010 13:52

Hi,

I have the following question: how to use images contained in a single .iml file in different classes, each one defined by its corresponding .h and .cpp file?

Cheers,

Javier

Hi Javier,

Just put
#define IMAGECLASS MyImages
#define IMAGEFILE images.iml
#include <Draw/iml_header.h>
in your headers and
#define IMAGECLASS MyImages
#define IMAGEFILE images.iml
#include <Draw/iml_source.h>
in one of your cpp files.

Best regards,
Honza
Re: Usage of images in different .h and .cpp files [message #27606 is a reply to message #27602] Sun, 25 July 2010 17:42 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
It does not work.

This is exactly what I’ve done:


1.- in the file “Prueba_OpenGL3.h” (this is the “main” .h file):
#define IMAGECLASS Imagenes
#define IMAGEFILE <prueba_OpenGL3/images.iml>
#include <Draw/iml_header.h>

2.- in the file “main .cpp” (obviously, this it the “main” .cpp file):
#define IMAGECLASS Imagenes
#define IMAGEFILE <prueba_OpenGL3/images.iml>
#include <Draw/iml_source.h>

3.- in the file “OpenGLExample.h” (this is a .h for class definition):
#define IMAGECLASS Imagenes
#define IMAGEFILE <prueba_OpenGL3/images.iml>
#include <Draw/iml_header.h>

4.- in the file “OpenGLExample.cpp”:
#define IMAGECLASS Imagenes
#define IMAGEFILE <prueba_OpenGL3/images.iml>
#include <Draw/iml_source.h>


To mention: there is an OpenGLExample object defined in the Prueba_OpenGL3.h file. Hence, I have included:
#include "OpenglExample.h"


There is one images.iml file, in which I would like to store all the images.

But this arrangement does not work.

Why?

Cheers,

Javier
Re: Usage of images in different .h and .cpp files [message #27608 is a reply to message #27606] Sun, 25 July 2010 18:51 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

You got it almost right Javier. The only problem is that iml_source.h must be included only once.

How it works: iml_header.h provides declarations, while iml_source.h provides definitions. So you must use iml_source.h only once, doesn't matter where, and only put the iml_header.h code in the rest of the places where necessary. Otherwise you get linker errors about multiple definitions.

In your case everything you have to do to get it work is to remove the definition from one of the cpp files (that is step 2 or step 4).

Honza
Re: Usage of images in different .h and .cpp files [message #27612 is a reply to message #27608] Sun, 25 July 2010 21:32 Go to previous message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Thanks.

I addition, I have realised that also
#define IMAGECLASS Imagenes 

must be declared only once in the multiple header files. Therefore, in my case (as I included the file “OpenGLExample.h as
#include "OpenglExample.h

the above mentioned “definition” has to be included in “OpenGLExample.h" only.

Cheers,

Javier
Previous Topic: Custom Control
Next Topic: How to compare child in function virtual void ChildMouseEvent with ctrl’s value.
Goto Forum:
  


Current Time: Fri Mar 29 08:54:58 CET 2024

Total time taken to generate the page: 0.02116 seconds