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

Author Topic: Static Window? "static sf::Window renderWindow;"  (Read 15395 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1839
    • View Profile
    • My GitHub Page
    • Email
Re: Static Window? "static sf::Window renderWindow;"
« Reply #45 on: October 28, 2012, 06:03:36 pm »
You can treat your classes like normal types and just put variable of your class type into your other class somewhere.
#include "B.h"
#include "C.h"
class A
{
private:
B my_b;
public:
C myPublicC;
}
That's the complete basics of c++ that you're missing.
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Static Window? "static sf::Window renderWindow;"
« Reply #46 on: October 28, 2012, 06:05:30 pm »
You can treat your classes like normal types and just put variable of your class type into your other class somewhere.
#include "B.h"
#include "C.h"
class A
{
private:
B my_b;
public:
C myPublicC;
}
That's the complete basics of c++ that you're missing.
So then.... Is B a class, and my_b refers to that class?

Aslo, what would be the difference between having that reference in private or public? It seems kinda odd I mean, another class wouldn't go to that class to get a reference member of the other class would it?

Also I just tried to change it in my ConsoleUtils..... It didn't work. It compiles. But it still does not get the proper variable... -nct is set to True, but it reads it as false.....

ConsoleUtils.h
#ifndef CONSOLEUTILS_H
#define CONSOLEUTILS_H
#include <string>
#include "Genesis.h"
//Debug Console font Modifications
class Font{
public:
    void set_color(short int a);
};
//A reference class for modifying, and adding things to the debuc console.
class Log{
public:
        Genesis genesis;
        void info(std::string a);
        void error(std::string a);
    void critical(std::string a);
};
class Validate{
public:
    bool Digits(const std::string& a);
};
#endif
 

Would it be possible, for you to show me a simple example of two files, with two different classes, say.... class A needs to get a bool variable from class B, but its in another file. How does it get that? Because apparently something I'm doing is wrong because I never can get the right data from my Genesis class.
« Last Edit: October 28, 2012, 06:12:34 pm by Flash619 »

FRex

  • Hero Member
  • *****
  • Posts: 1839
    • View Profile
    • My GitHub Page
    • Email
Re: Static Window? "static sf::Window renderWindow;"
« Reply #47 on: October 28, 2012, 06:11:14 pm »
B is the CLASS, my_B is object or instance of that class, it's independent of other objects of class B apart for static variables that all instances of one class share. Declared like this it will be constructed just before instance of A and live as long as that instance of A does. Go read some c++ tutorial, really.
http://www.parashift.com/c++-faq/overview-class.html
http://www.parashift.com/c++-faq/overview-object.html
ZipSavings, script to count rar/7z/zip savings: https://goo.gl/vvBj5M
LuaConsole: https://goo.gl/X4kRUk
FoxRaycaster: https://goo.gl/27nVS8
Small Games - Heart, Routing and Snek: https://goo.gl/15ZGWE https://goo.gl/k5gwWD https://goo.gl/4nKPnT
Botes - a notes app in Pascal: https://goo.gl/bzTqsi

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Static Window? "static sf::Window renderWindow;"
« Reply #48 on: October 28, 2012, 06:14:38 pm »
B is the CLASS, my_B is object or instance of that class, it's independent of other objects of class B apart for static variables that all instances of one class share. Declared like this it will be constructed just before instance of A and live as long as that instance of A does. Go read some c++ tutorial, really.
http://www.parashift.com/c++-faq/overview-class.html
http://www.parashift.com/c++-faq/overview-object.html

So you're saying if I want console utils to get

"NoConsoleTags"

From Genesis, that "NoConsoleTags" will have to be static?

Also thank you for the tutorial links...... I unfortunettely don't think I will pick up any knowledge from them. I mean sure I can read them, but whether I actually retain anything I'm reading is another story. I learn best from practical application. I mean, unless it actually says "This is how you send variables to other classes that are in other files" It's likely I wont know that that is what its for.

Its just frustrating right now because what I want, is really really simple, but I feel like you might be miss understanding what I want. Can it really be, that complicated to do this:

//MyFile
// .h
MyClass{

     bool MyVariable;

}
// .cpp
bool MyClass::MyVariable=false;
/*something in the class would happen and change that variable to true*/
/*It would then go to MyFile2 to do something else*/
//MyFile2
// .h
MyClass2{
#include MyClass;

MyClass myClass;

}
//.cpp
/*Some stuff happens in here, that gets that bool from MyClass, but it STILL RETAINS ITS VALUE of being true, and not its default of being false

It seems like it should be extremely easy stuff..... In fact... I'm pretty sure every program ever made does this at some point... >.>
« Last Edit: October 28, 2012, 06:33:18 pm by Flash619 »

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Static Window? "static sf::Window renderWindow;"
« Reply #49 on: October 28, 2012, 06:57:45 pm »
Just thought I would say, I have everything fixed! :D

The problem had nothing to do with how I was referencing my instance well it did. But here were the issues

1, I needed my variables to be static so they would share data across instances.

2,
        if((Genesis::WindowX>0)&&(Genesis::WindowY>0)&&(Genesis::Windowed=false))

Should have been

        if((Genesis::WindowX>0)&&(Genesis::WindowY>0)&&(Genesis::Windowed==false))

^^ That explains why it always appeared at default.

And my X/Y short ints also had to be made static.

Thank you for your generous help. It is greatly appreciated. Kudos to you!