0

I am newbie to this forum and my question is probably newbie-like too.

To be specific: I am working on a simple 2D game in SFML library, lang: C++. There would be an object which presents a brick. This is probably irrelevant. I would like my bricks to look the same on the screen, so i just made only one texture for them. And here is my problem:

I just declared an sf::Texture as a member of a brick class. The thing is that the texture is one and I don't want to load it or alloc memory for it every time I create new instance of brick class. I would like to create it only once in code and not change it anywhere else. So I thought I can make it static. Since texture in SFML is also a class I came across kind of mystery for me:

There is method LoadFromFile(). I would like to call it out to load my texture. How do I call out methods of the class which is static member of another class.

PS: This is probably the worst description you ever read. The truth is I can't describe anything to anyone. There is always more talking then facts etc. Hope you understood my issue.

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
xanax
  • 1
  • 1
    Welcome to stackoverflow.com. Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). You might also want to learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Oct 21 '15 at 07:50
  • You can create a "Texture class", load your texture loaded in a shared pointer and then pass this pointer to all your bricks. – Jepessen Oct 21 '15 at 08:47

1 Answers1

0

I'm not sure if I understand your problem right but answer on your general question "How do I call out methods of the class which is static member of another class" looks like crude code below:

#include <iostream>

class A 
{
   public:
   void printStr() { std::cout << "This is from A" << std::endl; };
};

class B
{
   public:
   // Static member declaration.
   static A a;
};

// Define a
A B::a;

int main()
{
   B::a.printStr();
   // or
   B b;
   b.a.printStr();
   return 0;
}
OlGu
  • 1
  • 2
  • `b.a.printStr()` afaik either (A) will not work or (B) is not the ideal syntax. I think it's better to use `parent::staticMember` syntax to clearly indicate you are using a static member. I go one step further and prefix `s_` to static members so I can determine this even _within_ the class (where `parent::` prefix generates a warning). – underscore_d Oct 21 '15 at 09:09