Invoking base constructor

Discussion in 'C++' started by Lilith, Dec 12, 2007.

  1. Lilith

    Lilith Guest

    I need to know if I'm doing something wrong here.

    I'm working with a library called SFML, an API for presenting
    graphics. I'm trying to inherit from a class called Image in order to
    make the class an is-a rather than a has-a entity.

    Here's the code, slightly stripped down to show just the constructor.

    #include "SFML\Graphics.hpp"

    class Grid : public sf::Image
    {
    public:


    Grid (int w, int h, sf::Color c) : sf::Image(w, h, c)
    {
    return;
    }

    };

    When the parent construct is invoked I get the following unhandled
    exception:

    Unhandled exception at 0x0000000f in MakeRoads.exe: 0xC0000005: Access
    violation reading location 0x0000000f.

    If I remove the invocation of the parent constructor I still get an
    error but it comes later when I try to plot a point that's outside the
    image size (0 x 0 by default) because the image didn't get initialized
    by the parent constructor.

    Anyone see the error of my approach?

    --
    Thanks,
    Lilith
     
    Lilith, Dec 12, 2007
    #1
    1. Advertising

  2. Lilith wrote:
    > I need to know if I'm doing something wrong here.
    >
    > I'm working with a library called SFML, an API for presenting
    > graphics. I'm trying to inherit from a class called Image in order to
    > make the class an is-a rather than a has-a entity.
    >
    > Here's the code, slightly stripped down to show just the constructor.
    >
    > #include "SFML\Graphics.hpp"


    #include "SFML/Graphics.hpp"

    >
    > class Grid : public sf::Image
    > {
    > public:
    >
    >
    > Grid (int w, int h, sf::Color c) : sf::Image(w, h, c)
    > {
    > return;
    > }
    >
    > };
    >
    > When the parent construct is invoked I get the following unhandled
    > exception:
    >
    > Unhandled exception at 0x0000000f in MakeRoads.exe: 0xC0000005: Access
    > violation reading location 0x0000000f.
    >
    > If I remove the invocation of the parent constructor I still get an
    > error but it comes later when I try to plot a point that's outside the
    > image size (0 x 0 by default) because the image didn't get initialized
    > by the parent constructor.
    >
    > Anyone see the error of my approach?


    No. The error must be elsewhere.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Dec 12, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dominique
    Replies:
    7
    Views:
    407
    amit gulati
    Nov 17, 2003
  2. mrstephengross
    Replies:
    5
    Views:
    623
    Larry I Smith
    May 18, 2005
  3. hurcan solter

    Invoking A Base class constructor

    hurcan solter, Jan 7, 2007, in forum: C++
    Replies:
    3
    Views:
    417
    Grizlyk
    Jan 12, 2007
  4. ali
    Replies:
    4
    Views:
    629
    David Harmon
    Mar 5, 2007
  5. Replies:
    2
    Views:
    748
Loading...

Share This Page