|
I have 2 classes, and both classes needs to know of each other. Here's the headers:
sprite.h
<br />
#ifndef SPRITE_H<br />
#define SPRITE_H<br />
#include "SDL.h"<br />
#include "SDLgraphics.h"<br />
<br />
class sprite<br />
{<br />
public:<br />
sprite( char * p_path, int p_noFrames );<br />
void Animate( SDLgraphics &p_g );<br />
SDL_Surface* GetSurface() { return m_image; }<br />
SDL_Rect* GetRect() { return &m_image->clip_rect; }<br />
protected:<br />
float m_x, m_y;<br />
int m_noFrames;<br />
int m_curFrame;<br />
SDL_Surface* m_image;<br />
<br />
};<br />
#endif<br />
SDLgraphics.h
<br />
#ifndef SDLgraphics_H<br />
#define SDLgraphics_H<br />
#include <cstdio><br />
#include <cstdlib><br />
#include "SDL.h"<br />
#include "sprite.h"<br />
<br />
class SDLgraphics<br />
{<br />
public:<br />
SDLgraphics(unsigned int p_flags);<br />
void Init(int p_width, int p_height);<br />
void Draw(sprite *p_sprite, SDL_Rect *p_area);<br />
inline void Draw(sprite *p_sprite);<br />
void Flip();<br />
protected:<br />
SDL_Surface *m_scene;<br />
<br />
};<br />
#endif<br />
When I try to compile it in Visual Studio 7.0 .NET I get error C2061: syntax error : identifier 'SDLgraphics', and another one relating to sprite.
Greatful for any help ;P
|
|
|
|
|
declare one class before defining the other :
sprite.h
<font style="color:blue;">#ifndef</font> SPRITE_H
<font style="color:blue;">#define</font> SPRITE_H
<font style="color:blue;">#include</font> "SDL.h"
<font style="color:blue;">#include</font> "SDLgraphics.h"
<font style="color:blue;">class </font>sprite {
<font style="color:blue;">public</font>:
sprite(<font style="color:blue;">char </font>* p_path, <font style="color:blue;">int </font>p_noFrames);
<font style="color:blue;">void </font>Animate(SDLgraphics &p_g);
SDL_Surface* GetSurface() { <font style="color:blue;">return </font>m_image; }
SDL_Rect* GetRect() { <font style="color:blue;">return </font>&m_image->clip_rect; }
<font style="color:blue;">protected</font>:
<font style="color:blue;">float </font>m_x, m_y;
<font style="color:blue;">int </font>m_noFrames;
<font style="color:blue;">int </font>m_curFrame;
SDL_Surface* m_image;
};
<font style="color:blue;">#endif</font>
SDLgraphics.h
<font style="color:blue;">#ifndef </font>SDLgraphics_H
<font style="color:blue;">#define</font> SDLgraphics_H
<font style="color:blue;">#include </font><unknown_file1.h> <font style="color:green;">
<font style="color:blue;">#include </font><unknown_file2.h> <font style="color:green;">
<font style="color:blue;">#include</font> "SDL.h"
<font style="color:blue;">#include </font>"sprite.h"
<font style="color:blue;">class </font>sprite; <font style="color:green;">
<font style="color:blue;">class </font>SDLgraphics {
<font style="color:blue;">public</font>:
SDLgraphics(<font style="color:blue;">unsigned int </font>p_flags);
<font style="color:blue;">void </font>Init(<font style="color:blue;">int </font>p_width, <font style="color:blue;">int </font>p_height);
<font style="color:blue;">void </font>Draw(sprite *p_sprite, SDL_Rect *p_area);
<font style="color:blue;">inline void </font>Draw(sprite *p_sprite);
<font style="color:blue;">void </font>Flip();
<font style="color:blue;">protected</font>:
SDL_Surface *m_scene;
};
<font style="color:blue;">#endif</font>
TOXCCT >>> GEII power
|
|
|
|
|
thx
|
|
|
|
|
Instead of including sprite.h in SDLGraphics.h try a forward declaration:
SDLgraphics.h
<br />
#ifndef SDLgraphics_H<br />
#define SDLgraphics_H<br />
#include <br />
#include <br />
#include "SDL.h"<br />
<br />
class sprite;<br />
<br />
class SDLgraphics<br />
{<br />
public<br />
...<br />
That should work in this case, because in SDLgraphics.h you only need sprite pointers.
Jens
|
|
|
|
|
Is it possible to monitor/hook a COM port that has been opened by another application?
|
|
|
|
|
I have installed Pladform SDK, but my code seems to refer to old .h files and not the new .h files. How do i make them link to my new .h files?
I have updated the environment variables as well.
Thanx.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
If you build your projects from DevStudio you also have to adjust your directory settings.
In VC 6 this is done in Tools->Options->Directories->Include Files
In VC 7+8 use Tools->Options->Projects->VC++ Directories
Jens
|
|
|
|
|
Tools->Options->Directories->Include Files
change the order using ALT+(UP/DOWN) ARROW and make ur platform sdk dir preferrably first one.
It's not a bug, it's an undocumented feature. suhredayan@omniquad.com
messenger :suhredayan@hotmail.com
|
|
|
|
|
Thanx for the reply, I did that as said in the microsoft site moving the directory up n down, still my app refers to old sdk files.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
This might be why you keep getting the old files, even though you updated the environment and other paths.
Header files included as 'part' of project.
If the SDK header files were included into your project, then it will use the files with their existing 'old' paths. You must open the workspace tree view, go to the 'files' tab, search under 'Header Files' and see if the old files are included in the list. If so, then remove them from the list by selecting and pressing delete key. Now, when one is required by your project, the new ones whould be located instead according to the environment variables.
|
|
|
|
|
What's the difference between 2 below implementations?
Case 1:
<br />
class animal{<br />
animal& operator=(animal& ani){<br />
return *this;<br />
}<br />
}<br />
Case 2:
<br />
class animal{<br />
animal operator=(animal& ani){<br />
return *this;<br />
}<br />
}<br />
Please note the reference sign (&) in return type of overloading operator.
Which implementation is correct?
Best regards.
|
|
|
|
|
|
when you return a reference, you will be able tou chain the operators like this:
animal MyAnimal1, MyAnimal2, MyAnimal3; <font style="color:green;">
MyAnimal1 = animal(<font style="color:green;"></font>); <font style="color:green;">
MyAnimal3 = MyAnimal2 = MyAnimal1; <font style="color:green;">
in general, we prefer the synopsis T& operator= (const T&) ...
make your choice
TOXCCT >>> GEII power
|
|
|
|
|
It may be a typo but if the code reflects what you have in your project you have missed a D out of DeleteMedia in the .cpp file.
In my experience if the function has not been defined in the header the autocompletion does not function.
Otherwise delete the project .ncb file and reload the project. This normally fixes such glitches.
Ant.
|
|
|
|
|
Two problems:
1. Intellisense sometimes has a problem with templates.
In that case you just have to type
2. You used a wrong syntax for declaring a template.
Also the methods of a template must be defined within
the header.
See the following example:
<br />
<br />
#include <vector><br />
using namespace std;<br />
<br />
template < class T > class CPlaylist<br />
{<br />
public:<br />
CPlaylist(T m_vPlaylist)<br />
{<br />
};<br />
virtual ~CPlaylist()<br />
{<br />
};<br />
void DeleteMedia(int iPosition);<br />
<br />
protected:<br />
std::vector< T > m_vPlaylist;<br />
...<br />
};<br />
<br />
template < class T > void CPlaylist< T >::DeleteMedia(int iPosition)<br />
{<br />
...<br />
}<br />
<br />
Jens
|
|
|
|
|
We said me that when I work with the templates I have to define the function in the header file when they are declared... Is it true ?
When I define:
std::vector <t> m_vPlaylist;
Is this call correct?
m_vPlaylist.Erase(iPosition);
When I write "m_vPlaylist." I can't see all the functions that work with vectors... For example "Erase" function.
|
|
|
|
|
Well, try it
Your linker will complain about missing functions...
You cannot define
std::vector m_vPlaylist;
since std::vector is a template and therefor
it needs a type, a specialization like
std::vector< int > m_vPlaylist;
which will generate a vector for storing ints.
But anyway you cannot call erase with an int parameter,
it takes an iterator.
Jens
|
|
|
|
|
Also note erase is all lower case.
Ant.
|
|
|
|
|
How to define a constructor when using Templates?
Here is the one I've declared:
template<class t=""> CPlaylist<t>::CPlaylist(T m_csName)
{
}
with those protected variables:
vector <t> m_vPlaylist;
CString m_csName;
No problem at compilation but the functions I've declared after are unabled...
Function's declaration:
template<class t=""> void CPlaylist<t>::MyFunction()
{
//smthg
}
|
|
|
|
|
<br />
template < class T > class CPlaylist<br />
{<br />
public:<br />
CPlaylist();<br />
CPlaylist(T m_vPlaylist);<br />
virtual ~CPlaylist();<br />
void DeleteMedia(int iPosition);<br />
<br />
protected:<br />
std::vector< T > m_vPlaylist;<br />
CString m_csName; <br />
};<br />
<br />
template < class T > CPlaylist< T >::CPlaylist()<br />
{<br />
};<br />
<br />
template < class T > CPlaylist< T >::CPlaylist(T m_vPlaylist)<br />
{<br />
};<br />
<br />
template < class T > CPlaylist< T >::~CPlaylist()<br />
{<br />
};<br />
<br />
template < class T > void CPlaylist< T >::DeleteMedia(int iPosition)<br />
{<br />
}<br />
<br />
Jens
|
|
|
|
|
Thank's!
I have one last question... How to initialyse a variable which type is CPlaylist ?
CPlaylist <t> MyVariable;
??
|
|
|
|
|
|
Well, that really depends on your implementation of CPlayList...
Jens
|
|
|
|
|
Here is how I declare my template in my .h:
template<class t=""> class CPlaylist
{
public:
CPlaylist(T m_vPlaylist);
virtual ~CPlaylist();
void DeleteMedia(int iPosition);
protected:
vector <t> m_vPlaylist;
CString m_csName;
};
In my .cpp, I define my function:
template<class t=""> void CPlaylist<t>:eleteMedia(int iPosition)
{
m_vPlaylist.Erase(iPosition);
}
That compiles but I have no access to all of the Vector function when I write a "." . I can't see them...
Some ideas about that?
|
|
|
|
|
If i set one time in my application, I hope that it can act like a clock to notify me to do something at that time.
How can i achieve this?? Is there any Win32 API which can do this or some sample code that i can reference??
Thank in advance
|
|
|
|