• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:46
CEST 04:46
KST 11:46
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244ByuL, and the Limitations of Standard Play3
Community News
Official StarCraft website teases new content ahead of BlizzCon?16Stellar Fest TWO the Moon (Dec 16-20)8Weekly Cups (August 24-30): Patches' balance mod takes over2New 3v3 BGH Ladder (and more) on ShieldBattery!40Weekly Cups (August 17-23): Zerg dominate the week6
StarCraft 2
General
Nexon wins bid to develop StarCraft IP content, distribute Overwatch mobile game SC4ALL: II Winner Will Earn a Spot at HSC 30! Balance hotfix patch 5.0.16b (July 16) September World Ranking: herO leads, Serral climbs Weekly Cups (August 10-16): SHIN doubles
Tourneys
IntoTheTV X SOOP SC2 League : Weekly & Monthly SC2 INu's Battles#20 [BO.9] 2026 GSTL Announcement Stellar Fest TWO the Moon (Dec 16-20) PIG STY FESTIVAL 8.0! (13 - 23 August)
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 541 Binary Choice The PondCast: SC2 News & Results Mutation # 540 Dodge This Mutation # 539 Thunder Dome
Brood War
General
Official StarCraft website teases new content ahead of BlizzCon? ASL22 General Discussion [Personal Project Share] Terran Defense v0.60 BW General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues KCM Race Survival 2026 Season 3 BSL LAN Party - Kraków 29-30 August - OPEN SIGNUPS [ASL22] Ro24 Group F
Strategy
Replay Review Process - What do you do? Game Theory for Starcraft Odyssey Mineral Stack Saturation Fighting Spirit mining rates
Other Games
General Games
Diablo IV EVE Corporation Nintendo Switch Thread [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Artificial Intelligence Thread UK Politics Mega-thread Things Aren’t Peaceful in Palestine
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Regacy Esports: The Bh…
regacyesports
Violent Games and Crime Rate…
TrAiDoS
LOCKPICKING NOOB
LUCKY_NOOB
Cathedral Of CS And NY pizza a…
FuDDx
Please support my new stand…
Peanutsc
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7921 users

The Big Programming Thread - Page 404

Forum Index > General Forum
Post a Reply
Prev 1 402 403 404 405 406 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Nausea
Profile Joined October 2010
Sweden807 Posts
December 03 2013 15:04 GMT
#8061
On December 03 2013 23:48 ThatGuy wrote:
Show nested quote +
On December 03 2013 22:40 Nausea wrote:
Ok! So your favorite noob is back with a question for c++.

I have 2 classes, both within the same namespace.
One of the classes calls upon the other with a function and one of the parameters is of the first class.
I try to send it with a "this" pointer and that can't be done because the compiler complains that i try to send namespacename::classname* instead of just the classname*.

I tried adding the namespace to the functions parameter but that didn't work.

Basically:

m_stateMachine.SetState(m_stateFactory->GetState(0), this, 0);

bool CStateMachine::SetState(CState* _state, CGame* _game, unsigned int _id)


Putting this might work:

bool CStateMachine::SetState(CState* _state, CGame* const _game, unsigned int _id)


I believe 'this' is a const pointer that cannot have its address modified.


Yeah I tried that but it didn't work.
Set it ablaze!
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
Last Edited: 2013-12-03 15:08:14
December 03 2013 15:05 GMT
#8062
That seems to be what's happening. Even if it shouldn't:

In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value
is the address of the object for which the function is called. The type of this in a member function of
a class X is X*. If the member function is declared const, the type of this is const X*, ....


Looks like a compiler bug to me.

*Edit: Surprised even that doesn't work. What compiler is this? :p
What happens if you call then function like this:

m_stateMachine.SetState(m_stateFactory->GetState(0), (CGame*)this, 0);
Nausea
Profile Joined October 2010
Sweden807 Posts
December 03 2013 15:13 GMT
#8063
On December 04 2013 00:05 iaretehnoob wrote:
That seems to be what's happening. Even if it shouldn't:
Show nested quote +

In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value
is the address of the object for which the function is called. The type of this in a member function of
a class X is X*. If the member function is declared const, the type of this is const X*, ....


Looks like a compiler bug to me.

*Edit: Surprised even that doesn't work. What compiler is this? :p
What happens if you call then function like this:

m_stateMachine.SetState(m_stateFactory->GetState(0), (CGame*)this, 0);


For some reason I can get all this to work, but not when I want to add namespace to all of it. As soon as I start to add namespace to it, it complains about that thing. I just don't get it.
Set it ablaze!
Nausea
Profile Joined October 2010
Sweden807 Posts
December 03 2013 15:24 GMT
#8064
Well at least this was a good learning experience. I learned to never use namespaces again.
Set it ablaze!
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 03 2013 20:12 GMT
#8065
On December 04 2013 00:24 Nausea wrote:
Well at least this was a good learning experience. I learned to never use namespaces again.

That's quite certainly the worst thing you could learn from this. Namespaces in C++ should be used sparingly, but they should be used.
If you have a good reason to disagree with the above, please tell me. Thank you.
Nausea
Profile Joined October 2010
Sweden807 Posts
December 03 2013 21:03 GMT
#8066
On December 04 2013 05:12 spinesheath wrote:
Show nested quote +
On December 04 2013 00:24 Nausea wrote:
Well at least this was a good learning experience. I learned to never use namespaces again.

That's quite certainly the worst thing you could learn from this. Namespaces in C++ should be used sparingly, but they should be used.


Ye of course I wasn't completely serious, just angered by the results.
Set it ablaze!
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
December 03 2013 23:08 GMT
#8067
Can you copy/paste your header file of CStateMachine?
Nausea
Profile Joined October 2010
Sweden807 Posts
December 04 2013 00:05 GMT
#8068
On December 04 2013 08:08 ThatGuy wrote:
Can you copy/paste your header file of CStateMachine?


Yeah sure.

+ Show Spoiler +
#ifndef CStateMachine_H
#define CStateMachine_H

/**
* Class CStateMachine
*Description: Manages the game states.
**/

#include "CState.h"

//namespace tpe {

class CStateMachine{

public:
// == Constructors
CStateMachine();
~CStateMachine();

// == Methods

void OnLoop(CGame* _game);

void OnDraw(CGame* _game);

void OnEvent(CGame* _game);

/**
* Set a new state, removes the old one to make space for the new one.
*
* \param _state The new state to make active.
* \param _game The game class.
* \param _id The state ID.
* \return Returns true if the state was set.
**/
bool SetState(CState* _state, CGame* const _game, unsigned int _id);
/**
* Destroys the current state.
*
* \param _game The game object to pass to the states before destroying them.
* \return Returns true. ATM
**/
bool RemoveCurSet(CGame* _game);

// == Members
CState* m_currentState;

};

//}

#endif

+ Show Spoiler +
#include "CStateMachine.h"

//namespace tpe{

CStateMachine::CStateMachine()
{
m_currentState = NULL;
}

CStateMachine::~CStateMachine()
{
m_currentState = NULL;
}

void CStateMachine::OnLoop(CGame* _game)
{

}

void CStateMachine::OnDraw(CGame* _game)
{

m_currentState->OnDraw(_game);

}

bool CStateMachine::SetState(CState* _state, CGame* const _game, unsigned int _id)
{

if(!RemoveCurSet(_game)) { return false; }
m_currentState = _state;
if(!_state) { return true; }
m_currentState->m_stateId = _id;
m_currentState->OnInit(_game);

return true;

}

bool CStateMachine::RemoveCurSet(CGame* _game)
{

if(!m_currentState) { return true;}
m_currentState->OnDestroy(_game);
delete m_currentState;
m_currentState = NULL;
return true;

}

void CStateMachine::OnEvent(CGame* _game)
{
m_currentState->OnEvent(_game);
}

//}
Set it ablaze!
Manit0u
Profile Blog Joined August 2004
Poland17838 Posts
Last Edited: 2013-12-04 00:13:50
December 04 2013 00:12 GMT
#8069
I've got a question for you: How do you go about password encryption this days?

Would something like this be feasible for a small system?


string GetEncryptedPassword(string input)
{
string salt = md5(input);

return md5(input + salt);
}


I know that md5 isn't secure any more, just using it as an example here. With this method I get to hit 2 birds with 1 stone:
a) I get a unique salt for each password
b) I don't have to store the salt anywhere in the databases
Time is precious. Waste it wisely.
obesechicken13
Profile Blog Joined July 2008
United States10467 Posts
Last Edited: 2013-12-04 03:29:52
December 04 2013 01:16 GMT
#8070
How do you group two joined xml files in xquery by an element?

I know how to join.
I know how to group. But I can't do both together...

nvm, figured out a way to do the problem with group by and a join using where clauses.
I think in our modern age technology has evolved to become more addictive. The things that don't give us pleasure aren't used as much. Work was never meant to be fun, but doing it makes us happier in the long run.
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
December 04 2013 01:27 GMT
#8071
On December 04 2013 09:05 Nausea wrote:
Show nested quote +
On December 04 2013 08:08 ThatGuy wrote:
Can you copy/paste your header file of CStateMachine?


Yeah sure.



Might be getting closer here...how does CStateMachine know of the existence of CGame? Is it declared in CState.h?
DeltaX
Profile Joined August 2011
United States287 Posts
December 04 2013 02:02 GMT
#8072
On December 04 2013 09:12 Manit0u wrote:
I've got a question for you: How do you go about password encryption this days?

Would something like this be feasible for a small system?


string GetEncryptedPassword(string input)
{
string salt = md5(input);

return md5(input + salt);
}


I know that md5 isn't secure any more, just using it as an example here. With this method I get to hit 2 birds with 1 stone:
a) I get a unique salt for each password
b) I don't have to store the salt anywhere in the databases


The first rule of crypto is don't roll your own crypto.

That said, salts (from what I can tell) are usually generated based on some combination of things like timestamp, username, ect to be as random as possible. The issue with what you are suggesting is that multiple people could have the same input, which means they have the same salt and same hashed passwords, just with a slightly more complex, but still trivial algorithm.

The best crypto methods will work even when the attacker knows exactly what you did, but they still can't do anything about it.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2013-12-04 05:11:34
December 04 2013 04:59 GMT
#8073
On December 04 2013 09:12 Manit0u wrote:
I've got a question for you: How do you go about password encryption this days?

Would something like this be feasible for a small system?


string GetEncryptedPassword(string input)
{
string salt = md5(input);

return md5(input + salt);
}


I know that md5 isn't secure any more, just using it as an example here. With this method I get to hit 2 birds with 1 stone:
a) I get a unique salt for each password
b) I don't have to store the salt anywhere in the databases


I use BCrypt, https://github.com/codahale/bcrypt-ruby

There's bindings for Java and C# as well I'm pretty sure.

Here's an example in Ruby
+ Show Spoiler +


class User
include Mongoid::Document
attr_accessor :password, :password_confirmation

field :name, :type => String
field :email, :type => String
field :crypted_password, :type => String

validates_presence_of (etc...)
validates_confirmation_of :password, :if => :password_required
validates_length_of :password, :within => 3..40, :if => :password_required
validates (etc...)

before_save :encrypt_password, :if => :password_required

def self.authenticate(email, password)
account = first(:conditions => { :email => /^#{email}$/i }) if email.present?
account && account.has_password?(password) ? account : nil
end

def has_password?(password)
::BCrypt::Password.new(crypted_password) == password
end

private
def encrypt_password
self.crypted_password = ::BCrypt::Password.create(self.password)
end

def password_required
crypted_password.blank? || self.password.present?
end
end



I use a before_save callback to call encrypt_password.

You should only save the password in the DB as encrypted, so GetPassword should never encrypt the password it should always return an already encrypted password.

If it is not a Getter and is a function that encrypts a password then the naming should be EncryptPassword, not GetPassword.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
Manit0u
Profile Blog Joined August 2004
Poland17838 Posts
December 04 2013 09:50 GMT
#8074
On December 04 2013 13:59 sluggaslamoo wrote:
Show nested quote +
On December 04 2013 09:12 Manit0u wrote:
I've got a question for you: How do you go about password encryption this days?

Would something like this be feasible for a small system?


string GetEncryptedPassword(string input)
{
string salt = md5(input);

return md5(input + salt);
}


I know that md5 isn't secure any more, just using it as an example here. With this method I get to hit 2 birds with 1 stone:
a) I get a unique salt for each password
b) I don't have to store the salt anywhere in the databases


I use BCrypt, https://github.com/codahale/bcrypt-ruby

There's bindings for Java and C# as well I'm pretty sure.

Here's an example in Ruby
+ Show Spoiler +


class User
include Mongoid::Document
attr_accessor :password, :password_confirmation

field :name, :type => String
field :email, :type => String
field :crypted_password, :type => String

validates_presence_of (etc...)
validates_confirmation_of :password, :if => :password_required
validates_length_of :password, :within => 3..40, :if => :password_required
validates (etc...)

before_save :encrypt_password, :if => :password_required

def self.authenticate(email, password)
account = first(:conditions => { :email => /^#{email}$/i }) if email.present?
account && account.has_password?(password) ? account : nil
end

def has_password?(password)
::BCrypt:assword.new(crypted_password) == password
end

private
def encrypt_password
self.crypted_password = ::BCrypt:assword.create(self.password)
end

def password_required
crypted_password.blank? || self.password.present?
end
end



I use a before_save callback to call encrypt_password.

You should only save the password in the DB as encrypted, so GetPassword should never encrypt the password it should always return an already encrypted password.

If it is not a Getter and is a function that encrypts a password then the naming should be EncryptPassword, not GetPassword.


I know, I just used a single function to do everything as a way to convey the meaning of the encryption method
Time is precious. Waste it wisely.
Nausea
Profile Joined October 2010
Sweden807 Posts
December 04 2013 11:52 GMT
#8075
On December 04 2013 10:27 ThatGuy wrote:
Show nested quote +
On December 04 2013 09:05 Nausea wrote:
On December 04 2013 08:08 ThatGuy wrote:
Can you copy/paste your header file of CStateMachine?


Yeah sure.



Might be getting closer here...how does CStateMachine know of the existence of CGame? Is it declared in CState.h?


It's forward declared in CState.h.
Set it ablaze!
Prillan
Profile Joined August 2011
Sweden350 Posts
December 04 2013 13:46 GMT
#8076
On December 04 2013 09:12 Manit0u wrote:
I've got a question for you: How do you go about password encryption this days?

Would something like this be feasible for a small system?


string GetEncryptedPassword(string input)
{
string salt = md5(input);

return md5(input + salt);
}


I know that md5 isn't secure any more, just using it as an example here. With this method I get to hit 2 birds with 1 stone:
a) I get a unique salt for each password
b) I don't have to store the salt anywhere in the databases


I recommend using some form of key stretching like PBKDF2. Read this carefully and make sure you understand it.

On another note, it's not password encryption. Encryption implies that you can decrypt it, which is not wanted here.
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
December 04 2013 15:30 GMT
#8077
Does anyone here like Objective-C? I'm starting to hate it with a passion by now. I find Java's syntax and way much better and easier.
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
December 04 2013 16:05 GMT
#8078
On December 04 2013 20:52 Nausea wrote:
Show nested quote +
On December 04 2013 10:27 ThatGuy wrote:
On December 04 2013 09:05 Nausea wrote:
On December 04 2013 08:08 ThatGuy wrote:
Can you copy/paste your header file of CStateMachine?


Yeah sure.



Might be getting closer here...how does CStateMachine know of the existence of CGame? Is it declared in CState.h?


It's forward declared in CState.h.


I think this may be your problem, the forward declaration might not be within the namespace.
Nausea
Profile Joined October 2010
Sweden807 Posts
December 04 2013 16:57 GMT
#8079
On December 05 2013 01:05 ThatGuy wrote:
Show nested quote +
On December 04 2013 20:52 Nausea wrote:
On December 04 2013 10:27 ThatGuy wrote:
On December 04 2013 09:05 Nausea wrote:
On December 04 2013 08:08 ThatGuy wrote:
Can you copy/paste your header file of CStateMachine?


Yeah sure.



Might be getting closer here...how does CStateMachine know of the existence of CGame? Is it declared in CState.h?


It's forward declared in CState.h.


I think this may be your problem, the forward declaration might not be within the namespace.


Ye I thought so too. Then I tried it and got the same error. ;(
Set it ablaze!
ThatGuy
Profile Blog Joined April 2008
Canada695 Posts
December 04 2013 17:01 GMT
#8080
Then let's continue the investigation ^^ can I see the CState.h? :D
Prev 1 402 403 404 405 406 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
22:30
Masters Cup #151
davetesta288
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
CosmosSc2 16
EnDerr 10
StarCraft: Brood War
Rain 2886
GuemChi 1777
actioN 160
Aegong 75
NaDa 52
Noble 30
Dota 2
NeuroSwarm128
League of Legends
Doublelift3888
Counter-Strike
summit1g5994
taco 607
Coldzera 258
minikerr113
Super Smash Bros
hungrybox763
Mew2King94
Other Games
shahzam447
Artosis329
C9.Mang0186
XaKoH 175
Maynarde99
ViBE93
Trikslyr48
Organizations
Other Games
BasetradeTV30
[ Show 14 non-featured ]
StarCraft 2
• EnkiAlexander 56
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Light_VIP 12
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota22194
League of Legends
• Lourlo172
• Stunt123
Other Games
• Scarra859
Upcoming Events
IntoTheTV X SOOP
8h 14m
CranKy Ducklings
1d 7h
Big Brain Bouts
1d 7h
Garitos vs ArT
Lambo vs Percival
TriGGeR vs ByuN
Sparkling Tuna Cup
2 days
OSC
2 days
Shopify Rebellion Sundays
2 days
Mixu vs TBD
Spirit vs TBD
Clem vs TBD
Patches Events
2 days
Afreeca Starleague
3 days
Soma vs Shuttle
BeSt vs Rush
WardiTV Weekly
3 days
Afreeca Starleague
4 days
Leta vs ggaemo
Jaedong vs Queen
[ Show More ]
GSL
4 days
PiGosaur Cup
4 days
Kung Fu Cup
5 days
Replay Cast
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-09-02
PiG Sty Festival 8.0
Light Tournament 2026

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
RSL Revival: Season 6
Calamity Invitational
Big Dog Cup 2026 Div 1
BLAST Open Fall 2026
Esports World Cup 2026
Esports World Cup 2026: LCQ
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5
Acropolis #5 - TRS
Escore Tournament S3: King of Kings
Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.