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

Author Topic: texture.loadFromFile() Function Does Not Work Globally?  (Read 1684 times)

0 Members and 1 Guest are viewing this topic.

Cryonic

  • Newbie
  • *
  • Posts: 16
    • View Profile
texture.loadFromFile() Function Does Not Work Globally?
« on: June 03, 2015, 03:19:28 am »
Hi, I have just started using SFML and encountered that the following will not work globally, but does work if I put it in my main() function (I am using C++):

sf::Texture texture;
texture.loadFromFile(image);

I will get the following exceptions for the "loadFromFile()" function line:
error C2143: syntax error : missing ';' before '.'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2371: 'texture' : redefinition; different basic types

The following is an exception for the Texture declaration line:
see declaration of 'texture'

Also, when placed globally, "texture" is underlined with a red squiggly line as if incorrect. (I am using VS 2013)

Any help would be greatly appreciated!

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: texture.loadFromFile() Function Does Not Work Globally?
« Reply #1 on: June 03, 2015, 03:44:55 am »
Do you really think the following kind code would work?

struct Foo
{
  void callSomeFunction() { }
};

Foo myFoo;
myFoo.callSomeFunction();

int main()
{
}

If you do then you really need to get yourself a good C++ book and learn the language before going any farther with SFML. Sorry to say it, but the problem you have has absolutely nothing to do with SFML besides the fact that you are using one of its types.

On a side note you really should avoid global variables as the singleton pattern is really an anti-pattern.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: texture.loadFromFile() Function Does Not Work Globally?
« Reply #2 on: June 03, 2015, 04:05:00 am »
...but does work if I put it in my main() function (I am using C++)
I think you solved your own problem  ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything