From doru-cat at ifi.uio.no  Thu May 22 04:26:50 2003
From: doru-cat at ifi.uio.no (Doru-Catalin Togea)
Date: Thu, 22 May 2003 10:26:50 +0200 (MEST)
Subject: Difficulty porting SMPEG player's "update" from C to C++
Message-ID: <Pine.SOL.4.51.0305221022370.17827@atta.ifi.uio.no>

Hi!

I am runing RedHat 7.3 with gcc 2.96.

I am trying to port the SMPEG player from C to C++, and I have a problem
which I do not understand, while porting the very "simple" update(...)
function:

The C programme is like this:

==================================================================
#include ...

// the function I have problems with:
void update(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
{
    if ( screen->flags & SDL_DOUBLEBUF ) {
        SDL_Flip(screen);
    }
}

main(int argc, char *argv[])
{
...
  if ( info.has_video && use_video ) {
    ...
    SMPEG_setdisplay(mpeg, screen, NULL, update); // update called here
                                                  // by referance
  }
...
}
==================================================================


In my C++ programme I have a class declared as follows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class MPEGPlayer : public Module {
 private:
  ...
  // cut-and-paste from the C programme
  void update(SDL_Surface *screen,
	      Sint32 x, Sint32 y, Uint32 w, Uint32 h);

  // the C'programme's main routine's code
  // will be run here:
  static void *playMPEG (void *threadArgs);
 public:
  ...
};

void MPEGPlayer::update(SDL_Surface *screen,
			Sint32 x, Sint32 y, Uint32 w, Uint32 h)
{
    if ( screen->flags & SDL_DOUBLEBUF ) {
        SDL_Flip(screen);
    }
}

// basically the same code as the C programme's main routine:
void *MPEGPlayer::playMPEG(void *threadArgs)
{
...
  if ( info.has_video && use_video ) {
    ...
    SMPEG_setdisplay(mpeg, screen, NULL, update); // update called here
                                                  // by referance
  }
...
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I try to compile my C++ programme (which uses the MPEGPlayer class) with
the following command:

[...]$ g++ `sdl-config --cflags --libs`
-I/usr/include/smpeg/  -lsmpeg -lSDL -o receiver receiver.cpp

I get the following error message:

In file included from receiver.cpp:10:
mpegPlayer.h: In function `void *MPEGPlayer::playMPEG (void *)':
mpegPlayer.h:385: no matches converting function `update' to type `void
(*) (struct SDL_Surface *, int, int, unsigned int, unsigned int)'
mpegPlayer.h:219: candidates are: void MPEGPlayer::update (SDL_Surface
*, int, int, unsigned int, unsigned int)

Can anyone tell me what I am doing wrong?

Thanks a lot,
Catalin

-- 

	<<<< ================================== >>>>
	<<     We are what we repeatedly do.      >>
	<<  Excellence, therefore, is not an act  >>
	<<             but a habit.               >>
	<<<< ================================== >>>>


From slimb at swes.saren.ru  Thu May 22 05:54:42 2003
From: slimb at swes.saren.ru (Ed Sinjiashvili)
Date: Thu, 22 May 2003 13:54:42 +0400
Subject: [smpeg] Difficulty porting SMPEG player's "update" from C to C++
In-Reply-To: <Pine.SOL.4.51.0305221022370.17827@atta.ifi.uio.no>
References: <Pine.SOL.4.51.0305221022370.17827@atta.ifi.uio.no>
Message-ID: <20030522135442.232ce283.slimb@swes.saren.ru>

On Thu, 22 May 2003 10:26:50 +0200 (MEST)
Doru-Catalin Togea <doru-cat at ifi.uio.no> wrote:

> I get the following error message:
> 
> In file included from receiver.cpp:10:
> mpegPlayer.h: In function `void *MPEGPlayer::playMPEG (void *)':
> mpegPlayer.h:385: no matches converting function `update' to type `void
> (*) (struct SDL_Surface *, int, int, unsigned int, unsigned int)'
> mpegPlayer.h:219: candidates are: void MPEGPlayer::update (SDL_Surface
> *, int, int, unsigned int, unsigned int)
> 
> Can anyone tell me what I am doing wrong?
It's hard to tell from the info you provided. 
Maybe you're trying to call member function 'update' from *static* method playMPEG without explicitly specifying object which is meant to be updated. Something like this?

void *MPEGPlayer::playMPEG(void *)
{
	update(bla, bla, bla); // static method - no implicit this here
}

In this case you must either declare 'update' as a static method or provide an instance to 
which update will be applied.

Anyway this looks like an off-topic to me. Contact me off-list if you please and I will try to help you.

-- Ed



From icculus at clutteredmind.org  Thu May 22 21:00:32 2003
From: icculus at clutteredmind.org (Ryan C. Gordon)
Date: Thu, 22 May 2003 21:00:32 -0400 (EDT)
Subject: [smpeg] Difficulty porting SMPEG player's "update" from C to
 C++
In-Reply-To: <Pine.SOL.4.51.0305221022370.17827@atta.ifi.uio.no>
Message-ID: <Pine.LNX.4.33.0305222057260.1068-100000@wickedsick>


>   // cut-and-paste from the C programme
>   void update(SDL_Surface *screen,
> 	      Sint32 x, Sint32 y, Uint32 w, Uint32 h);

Make this "static".

static void update( /* etc... */ );

>     SMPEG_setdisplay(mpeg, screen, NULL, update); // update called here
>                                                   // by referance

you might want to specify &MPEGPlayer::update.

> Can anyone tell me what I am doing wrong?

You're trying to pass a class method to something that wants a straight C
function. Unless you specify that method to be "static", it'd expect you
to pass a "this" pointer to the function.

Being static means it can't touch any instance members of the class, though.

--ryan.





From doru-cat at ifi.uio.no  Fri May 23 03:59:27 2003
From: doru-cat at ifi.uio.no (Doru-Catalin Togea)
Date: Fri, 23 May 2003 09:59:27 +0200 (MEST)
Subject: [smpeg] Difficulty porting SMPEG player's "update" from C to
 C++
In-Reply-To: <20030522135442.232ce283.slimb@swes.saren.ru>
References: <Pine.SOL.4.51.0305221022370.17827@atta.ifi.uio.no>
 <20030522135442.232ce283.slimb@swes.saren.ru>
Message-ID: <Pine.SOL.4.51.0305230949540.10837@einn.ifi.uio.no>

On Thu, 22 May 2003, Ed Sinjiashvili wrote:

> In this case you must either declare 'update' as a static method or
> provide an instance to which update will be applied.

Indeed, as several of you have pointed out, one solution is to make the
method static. Thanks to everyone for hints and explanations. I am very
relieved to have a working MPEG-playback module.

> Anyway this looks like an off-topic to me. Contact me off-list if you
please and I will try to help you.

Is this list only for developers? My programme is after all using
the SMPEG library in a specific context.

Catalin


-- 

	<<<< ================================== >>>>
	<<     We are what we repeatedly do.      >>
	<<  Excellence, therefore, is not an act  >>
	<<             but a habit.               >>
	<<<< ================================== >>>>


From icculus at clutteredmind.org  Fri May 23 23:50:11 2003
From: icculus at clutteredmind.org (Ryan C. Gordon)
Date: Fri, 23 May 2003 23:50:11 -0400 (EDT)
Subject: [smpeg] Difficulty porting SMPEG player's "update" from C to
 C++
In-Reply-To: <Pine.SOL.4.51.0305230949540.10837@einn.ifi.uio.no>
Message-ID: <Pine.LNX.4.33.0305232348550.17293-100000@wickedsick>


> Is this list only for developers? My programme is after all using
> the SMPEG library in a specific context.

It's not really offtopic (considering how extremely low-traffic this list
is), so long as we don't degenerate into a General C++ Programming FAQ.  :)

Glad to hear your code is working!

--ryan.





