Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: i didnt want to post it ^^  (Read 3218 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
i didnt want to post it ^^
« on: October 05, 2008, 11:41:45 am »
Code: [Select]
class Missile
{
public :

    static bool Init(const std::string& ImageFile)
    {
        return Image.LoadFromFile(ImageFile);
    }

    Missile()
    {
        Sprite.SetImage(Image); // every sprite uses the same unique image
    }

private :

    static sf::Image Image; // shared by every instance

    sf::Sprite Sprite; // one per instance
};


 i want this to be in seperate files, but
Code: [Select]

#include "sfml-graphic.hpp"
class Missile
{
public :

    static bool Init(const std::string& ImageFile);
    Missile();

private :
    static sf::Image Image; // shared by every instance
    sf::Sprite Sprite; // one per instance
};

in .h and


Code: [Select]


#includes

static bool Missile::Init(...)
{
return Image.LoadFromFile(...)
}

Missile::Missile()
    {
        Sprite.SetImage(Image); // every sprite uses the same unique image
    }

doesnt work

i already asked in a c++ forum but i dont get a answer

edit : code::blocks says :
C:\Programme\CodeBlocks\MEINS\Object\object.cpp|16|error: cannot declare member function `static bool object::Init(const std::string&)' to have static linkage|
||=== Build finished: 1 errors, 0 warnings ===|

InconnuConnu

  • Newbie
  • *
  • Posts: 12
    • View Profile
i didnt want to post it ^^
« Reply #1 on: October 05, 2008, 11:50:39 am »
You don't need the static keyword in the function definition inside the cpp file.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
i didnt want to post it ^^
« Reply #2 on: October 05, 2008, 11:53:08 am »
then i get:
||Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE |
||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.obj\Debug\object.o||In function `_ZN6object4InitERKSs':|
C:\Programme\CodeBlocks\MEINS\Object\object.cpp|16|undefined reference to `object::Image'|
obj\Debug\object.o||In function `_ZN6objectC2Ev':|
C:\Programme\CodeBlocks\MEINS\Object\object.cpp|21|undefined reference to `object::Image'|
obj\Debug\object.o||In function `_ZN6objectC1Ev':|
C:\Programme\CodeBlocks\MEINS\Object\object.cpp|21|undefined reference to `object::Image'|
||=== Build finished: 3 errors, 1 warnings ===|

edit: replace Missile with object

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
i didnt want to post it ^^
« Reply #3 on: October 05, 2008, 12:23:08 pm »
This should work:

Missile.h
Code: [Select]
#include <SFML/Graphics.hpp>

class Missile
{
public :

    Missile();

    static bool Init(const std::string& ImageFile);

private :

    static sf::Image Image; // shared by every instance

    sf::Sprite Sprite; // one per instance
};


Missile.cpp
Code: [Select]
sf::Image Missile::Image;

Missile::Missile()
{
Sprite.SetImage(Image); // every sprite uses the same unique image
}

bool Missile::Init(const std::string& ImageFile)
{
return Image.LoadFromFile(ImageFile);
}


Maybe you should read a book about C++.

 

anything