• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:26
CEST 03:26
KST 10:26
  • 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
RSL Season 1 - Final Week6[ASL19] Finals Recap: Standing Tall12HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Esports World Cup 2025 - Brackets Revealed7Weekly Cups (July 7-13): Classic continues to roll2Team TLMC #5 - Submission extension2Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7
StarCraft 2
General
Esports World Cup 2025 - Brackets Revealed Who will win EWC 2025? Team TLMC #5 - Submission extension The GOAT ranking of GOAT rankings Esports World Cup 2025 - Final Player Roster
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event $5,100+ SEL Season 2 Championship (SC: Evo) WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
BW General Discussion Flash Announces (and Retracts) Hiatus From ASL Starcraft in widescreen BGH Auto Balance -> http://bghmmr.eu/ A cwal.gg Extension - Easily keep track of anyone
Tourneys
Cosmonarchy Pro Showmatches [Megathread] Daily Proleagues CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile CCLP - Command & Conquer League Project The PlayStation 5
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Summer Games Done Quick 2025! Things Aren’t Peaceful in Palestine Stop Killing Games - European Citizens Initiative
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 2024 - 2025 Football Thread NBA General Discussion NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 483 users

The Big Programming Thread - Page 601

Forum Index > General Forum
Post a Reply
Prev 1 599 600 601 602 603 1031 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.
r3dox
Profile Blog Joined May 2003
Germany261 Posts
March 05 2015 18:55 GMT
#12001
On March 06 2015 03:20 heartlxp wrote:
hi guys, anyone else have problem with frontend caching?

we make changes to html/js, but we have to clear cache in our browsers to see them. this happens generally for modals and dropdown menus. we use Angularjs/nginx if that's relevant at all.

when developing it's trivial to refresh, but we can't force all users to clear cache every time we update...any ideas?


you should probably configure your nginx webserver to send appropriate Cache http headers for your files.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
March 05 2015 22:15 GMT
#12002
does anybody know how I can get the pointer to the struct?



void PrintAllComponents(Entity entity){
auto comp= entity.GetComponent(1);
cout << comp->HP << endl;
}

class Component
{
public:
int GetComponentID();
Entity* GetParent();
void SetParent(Entity* entity);
void SetComponentID(int ComponentID);

int ComponentID;
Entity* m_Parent;
};

struct Health : public Component
{
Health(int HP, int max);
int HP;
int max;
};

Health::Health(int maxhp , int hp){
HP=hp;
max=maxhp;
SetComponentID(1);
}

void Entity::AddComponent(Component* cmp){
m_components[cmp->GetComponentID()] = cmp;
cmp->SetParent(this);
}

struct Entity
{
Component* GetComponent(int id);
virtual void AddComponent(Component* Component);
std::map<int,Component *>m_components;
};


int main(){

Entity one;

Health test(50,30);
one.AddComponent(&test);
PrintAllComponents();
}

The harder it becomes, the more you should focus on the basics.
Acrofales
Profile Joined August 2010
Spain17975 Posts
March 05 2015 22:31 GMT
#12003
On March 06 2015 07:15 sabas123 wrote:
does anybody know how I can get the pointer to the struct?



void PrintAllComponents(Entity entity){
auto comp= entity.GetComponent(1);
cout << comp->HP << endl;
}

class Component
{
public:
int GetComponentID();
Entity* GetParent();
void SetParent(Entity* entity);
void SetComponentID(int ComponentID);

int ComponentID;
Entity* m_Parent;
};

struct Health : public Component
{
Health(int HP, int max);
int HP;
int max;
};

Health::Health(int maxhp , int hp){
HP=hp;
max=maxhp;
SetComponentID(1);
}

void Entity::AddComponent(Component* cmp){
m_components[cmp->GetComponentID()] = cmp;
cmp->SetParent(this);
}

struct Entity
{
Component* GetComponent(int id);
virtual void AddComponent(Component* Component);
std::map<int,Component *>m_components;
};


int main(){

Entity one;

Health test(50,30);
one.AddComponent(&test);
PrintAllComponents();
}



Why not just initialize it as Entity* one = new Entity();

?

Rollin
Profile Joined March 2011
Australia1552 Posts
March 05 2015 22:47 GMT
#12004
Because this isn't the 90's? You [almost always] shouldn't have raw new/deletes floating around outside of constructors/destructors, especially once exceptions start coming into play. A more modern approach for a heap object would be:

std::unique_ptr<Entity>(new Entity()) entity;
// if you need a raw pointer, either assign it, or use entity.get() directly
auto rawPtr = entity.get();
Throw off those chains of reason, and your prison disappears. | Check your posting frequency timeline: http://www.teamliquid.net/mytlnet/post_activity_img.php
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-03-05 23:52:10
March 05 2015 23:48 GMT
#12005
In any case there's a lot of other things wrong with the code sample that I'm not sure what the question is asking... seems pretty straightforward since they've already used the &test but yeah
There is no one like you in the universe.
teamamerica
Profile Blog Joined July 2010
United States958 Posts
March 06 2015 00:00 GMT
#12006
On March 06 2015 03:20 heartlxp wrote:
hi guys, anyone else have problem with frontend caching?

we make changes to html/js, but we have to clear cache in our browsers to see them. this happens generally for modals and dropdown menus. we use Angularjs/nginx if that's relevant at all.

when developing it's trivial to refresh, but we can't force all users to clear cache every time we update...any ideas?


Afaik people do cache busting by having some random number as part of query parameter. You have you webserver turn request for asset.css?cachebust=12345 to serve back asset.css.
RIP GOMTV. RIP PROLEAGUE.
Cyx.
Profile Joined November 2010
Canada806 Posts
Last Edited: 2015-03-06 01:00:18
March 06 2015 00:59 GMT
#12007
On March 06 2015 07:47 Rollin wrote:
Because this isn't the 90's? You [almost always] shouldn't have raw new/deletes floating around outside of constructors/destructors, especially once exceptions start coming into play. A more modern approach for a heap object would be:

std::unique_ptr<Entity>(new Entity()) entity;
// if you need a raw pointer, either assign it, or use entity.get() directly
auto rawPtr = entity.get();

Why not just
Entity *p = &one
?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-03-06 02:36:06
March 06 2015 01:18 GMT
#12008
std::shared_ptr<Entity> entity(new Entity());

is where it's at

or even
std::shared_ptr<Entity> entity = std::make_shared<Entity>()


For school assignments and stuff unless the project is pretty big I prefer just raw pointering. At some point I'll switch over to smart pointers if the project gets large large and I'm doing thread dangerous stuff, but normal pointers and references are less verbose and easier to use - I don't have to search up documentation on whether I want shared_ptr, unique_ptr, weak_ptr, swap(), reset(), get(), use_count() or other stuff. Yes I know just use shared_ptr everywhere but at that point it's almost the same as use raw pointers - I very rarely get burned from allocations and forgetting about deleting memory from the way I code and if I do it's usually because I've been overly zealous with deleting and I'm deleting a pointer twice.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-03-06 01:37:27
March 06 2015 01:25 GMT
#12009
edit: nevermind solved it
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
March 06 2015 07:19 GMT
#12010
On March 06 2015 08:48 Blisse wrote:
In any case there's a lot of other things wrong with the code sample that I'm not sure what the question is asking... seems pretty straightforward since they've already used the &test but yeah

well im trying to acces the variable of struct hp, that I linked to an entity. I can get the adress of hp but somehow not the variable members
The harder it becomes, the more you should focus on the basics.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-03-06 07:40:53
March 06 2015 07:33 GMT
#12011
On March 06 2015 16:19 sabas123 wrote:
Show nested quote +
On March 06 2015 08:48 Blisse wrote:
In any case there's a lot of other things wrong with the code sample that I'm not sure what the question is asking... seems pretty straightforward since they've already used the &test but yeah

well im trying to acces the variable of struct hp, that I linked to an entity. I can get the adress of hp but somehow not the variable members


Sorry I can't debug the code unless I ask, does your code compile? I'm really hoping what you posted is just random snippets of some other system...

you didn't pass the entity one to printallcomponents, entity::addcomponent is defined before you declared the entity struct, things, i can't look at that code and suggest a solution when there's just so much wrong/inconsistent already, a lot of potentially broken pathways... if you link the entire source i could be more specific...

Just looking at your code, I'd assume because you're mixing passing by value with passing pointers you're not setting things properly, just throw couts everywhere or step through gdb and you'll find somethings not set and saved properly
There is no one like you in the universe.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
March 06 2015 09:06 GMT
#12012
ok I found the problem, kinda

I am passing a Component * so I can't access the derived members variablesT_T
The harder it becomes, the more you should focus on the basics.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2015-03-06 10:12:01
March 06 2015 10:08 GMT
#12013
that makes sense :p

really surprised the compiler let that compile though
There is no one like you in the universe.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
March 06 2015 11:32 GMT
#12014
On March 06 2015 19:08 Blisse wrote:
that makes sense :p

really surprised the compiler let that compile though

now just have to find a way to typecast everything:/
The harder it becomes, the more you should focus on the basics.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
March 06 2015 12:08 GMT
#12015
On March 06 2015 20:32 sabas123 wrote:
Show nested quote +
On March 06 2015 19:08 Blisse wrote:
that makes sense :p

really surprised the compiler let that compile though

now just have to find a way to typecast everything:/

Instead of casting, try finding a better design.
If you have a good reason to disagree with the above, please tell me. Thank you.
sabas123
Profile Blog Joined December 2010
Netherlands3122 Posts
March 06 2015 12:54 GMT
#12016
On March 06 2015 21:08 spinesheath wrote:
Show nested quote +
On March 06 2015 20:32 sabas123 wrote:
On March 06 2015 19:08 Blisse wrote:
that makes sense :p

really surprised the compiler let that compile though

now just have to find a way to typecast everything:/

Instead of casting, try finding a better design.

the whole design is ok in my opinion, just this part is annoying as fuck.
The harder it becomes, the more you should focus on the basics.
Rollin
Profile Joined March 2011
Australia1552 Posts
Last Edited: 2015-03-06 13:01:29
March 06 2015 13:00 GMT
#12017
On March 06 2015 10:18 Blisse wrote:
+ Show Spoiler +

std::shared_ptr<Entity> entity(new Entity());

is where it's at

or even
std::shared_ptr<Entity> entity = std::make_shared<Entity>()


For school assignments and stuff unless the project is pretty big I prefer just raw pointering. At some point I'll switch over to smart pointers if the project gets large large and I'm doing thread dangerous stuff, but normal pointers and references are less verbose and easier to use - I don't have to search up documentation on whether I want shared_ptr, unique_ptr, weak_ptr, swap(), reset(), get(), use_count() or other stuff. Yes I know just use shared_ptr everywhere but at that point it's almost the same as use raw pointers - I very rarely get burned from allocations and forgetting about deleting memory from the way I code and if I do it's usually because I've been overly zealous with deleting and I'm deleting a pointer twice.


Shared pointer just has a threadsafe reference count attached. For projects that aren't under performance constraints, as you say, using shared pointer indiscriminately isn't an issue in the slightest. All unique pointer does is free resources when it goes out of scope (rather than when all references to it go out of scope in shared_ptr), although the lack of make_unique in c++11 obfuscates the initialisation syntax somewhat. However for the single ownership model (most of the time code can be made to fit this), unique_ptr is the wrapper of choice.
Throw off those chains of reason, and your prison disappears. | Check your posting frequency timeline: http://www.teamliquid.net/mytlnet/post_activity_img.php
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2015-03-06 20:04:44
March 06 2015 20:02 GMT
#12018
nevermind again lol

figure out the answers to my own questions as i post them. sorry everyone
Cyx.
Profile Joined November 2010
Canada806 Posts
March 06 2015 20:30 GMT
#12019
On March 07 2015 05:02 travis wrote:
nevermind again lol

figure out the answers to my own questions as i post them. sorry everyone

haha it's all part of the Rubber Ducky process don't worry
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2015-03-07 01:26:32
March 07 2015 01:20 GMT
#12020
On March 06 2015 21:54 sabas123 wrote:
Show nested quote +
On March 06 2015 21:08 spinesheath wrote:
On March 06 2015 20:32 sabas123 wrote:
On March 06 2015 19:08 Blisse wrote:
that makes sense :p

really surprised the compiler let that compile though

now just have to find a way to typecast everything:/

Instead of casting, try finding a better design.

the whole design is ok in my opinion, just this part is annoying as fuck.


Nope, it's not. The whole idea of using derived classes when a base class is expected is that you respect interface. An interface is like a contract. Derived classes can have different behaviour but interface shouldn't be violated. On a funny note, this applies to your case.

[image loading]

Anyway, if it's the HP field that you want to access, then make it a protected field in the base class. If this isn't what you want, you should indeed reconsider design.

On March 06 2015 07:31 Acrofales wrote:


Why not just initialize it as Entity* one = new Entity();

?



As far as I know, C++ prefers stack objects as much as possible. Don't be mistaken with languages like Java and C# where 'new' is a no-brainer.
Prev 1 599 600 601 602 603 1031 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
SEL Masters #4 - Day 2
CranKy Ducklings111
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 210
Livibee 130
ProTech55
StarCraft: Brood War
Artosis 836
Icarus 4
Dota 2
monkeys_forever861
NeuroSwarm150
League of Legends
JimRising 748
Trikslyr89
Counter-Strike
Fnx 1563
taco 347
Super Smash Bros
hungrybox766
Other Games
summit1g14628
shahzam1706
Day[9].tv395
C9.Mang0230
Maynarde153
Mew2King31
RuFF_SC219
Organizations
Other Games
gamesdonequick3522
BasetradeTV37
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH136
• Mapu4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift6170
• Scarra1661
Other Games
• Day9tv395
Upcoming Events
Replay Cast
8h 35m
WardiTV European League
14h 35m
ShoWTimE vs sebesdes
Percival vs NightPhoenix
Shameless vs Nicoract
Krystianer vs Scarlett
ByuN vs uThermal
Harstem vs HeRoMaRinE
PiGosaur Monday
22h 35m
uThermal 2v2 Circuit
1d 14h
Replay Cast
1d 22h
The PondCast
2 days
Replay Cast
2 days
Epic.LAN
3 days
CranKy Ducklings
4 days
Epic.LAN
4 days
[ Show More ]
BSL20 Non-Korean Champi…
4 days
Bonyth vs Sziky
Dewalt vs Hawk
Hawk vs QiaoGege
Sziky vs Dewalt
Mihu vs Bonyth
Zhanhun vs QiaoGege
QiaoGege vs Fengzi
Sparkling Tuna Cup
5 days
Online Event
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Zhanhun
Dewalt vs Mihu
Hawk vs Sziky
Sziky vs QiaoGege
Mihu vs Hawk
Zhanhun vs Dewalt
Fengzi vs Bonyth
Liquipedia Results

Completed

2025 ACS Season 2: Qualifier
RSL Revival: Season 1
Murky Cup #2

Ongoing

JPL Season 2
BSL 2v2 Season 3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
Championship of Russia 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
K-Championship
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
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 © 2025 TLnet. All Rights Reserved.