• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 23:02
CET 05:02
KST 13:02
  • 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
Rongyi Cup S3 - Preview & Info3herO wins SC2 All-Star Invitational12SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0
Community News
Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)25Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7
StarCraft 2
General
PhD study /w SC2 - help with a survey! herO wins SC2 All-Star Invitational Oliveira Would Have Returned If EWC Continued StarCraft 2 not at the Esports World Cup 2026 [Short Story] The Last GSL
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open! SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 510 Safety Violation Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained
Brood War
General
[ASL21] Potential Map Candidates Which foreign pros are considered the best? Gypsy to Korea BGH Auto Balance -> http://bghmmr.eu/ Fantasy's Q&A video
Tourneys
[Megathread] Daily Proleagues Azhi's Colosseum - Season 2 Small VOD Thread 2.0 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Current Meta Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Beyond All Reason Awesome Games Done Quick 2026!
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Canadian Politics Mega-thread NASA and the Private Sector
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
How Esports Advertising Shap…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1496 users

The Big Programming Thread - Page 265

Forum Index > General Forum
Post a Reply
Prev 1 263 264 265 266 267 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.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-03-08 17:26:40
March 08 2013 14:30 GMT
#5281
nvm, fixed.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2013-03-08 14:40:28
March 08 2013 14:37 GMT
#5282
On March 08 2013 12:15 nunez wrote:
why does 'done' have to be public for this to compile?
class listener{
atomic<bool> done{false};
thread worker{
[this](){
while(!(this->done.load())){
this_thread::sleep_for(chrono::milliseconds(100));
}
}
};
public:
listener(){}
~listener(){
done.store(true);
worker.join();
}
};

testing.cpp:9:28: error: ‘std::atomic<bool> listener::done’ is private
testing.cpp:12:18: error: within this context


Lambda expressions are basically global functions, even if you create them inside the scope of a class. Global functions don't have access to the private members of any class' object, so you need to make it public. If you want it to work with "done" still being private, you have to capture it in the "[]" of the lambda, so either "[&done]" to capture the variable manually by reference, or "[&]" to capture everything in the current scope by reference (you can capture it by value too, but considering the semantics of your class this would be nonsensical).
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
memcpy
Profile Blog Joined April 2010
United States459 Posts
March 08 2013 14:55 GMT
#5283
On March 08 2013 12:15 nunez wrote:
why does 'done' have to be public for this to compile?
class listener{
atomic<bool> done{false};
thread worker{
[this](){
while(!(this->done.load())){
this_thread::sleep_for(chrono::milliseconds(100));
}
}
};
public:
listener(){}
~listener(){
done.store(true);
worker.join();
}
};

testing.cpp:9:28: error: ‘std::atomic<bool> listener::done’ is private
testing.cpp:12:18: error: within this context


Probably a compiler bug. Seems to work fine with using an initializer list.

#include <atomic>
#include <thread>
using namespace std;

class listener{
atomic<bool> done;
thread worker;
public:
listener() :
done(false),
worker([this](){
while(!(this->done.load())){
this_thread::sleep_for(chrono::milliseconds(100));
}
}){}

~listener(){
done.store(true);
worker.join();
}
};
memcpy
Profile Blog Joined April 2010
United States459 Posts
March 08 2013 15:16 GMT
#5284
On March 08 2013 23:37 heishe wrote:
Show nested quote +
On March 08 2013 12:15 nunez wrote:
why does 'done' have to be public for this to compile?
class listener{
atomic<bool> done{false};
thread worker{
[this](){
while(!(this->done.load())){
this_thread::sleep_for(chrono::milliseconds(100));
}
}
};
public:
listener(){}
~listener(){
done.store(true);
worker.join();
}
};

testing.cpp:9:28: error: ‘std::atomic<bool> listener::done’ is private
testing.cpp:12:18: error: within this context


Lambda expressions are basically global functions, even if you create them inside the scope of a class. Global functions don't have access to the private members of any class' object, so you need to make it public. If you want it to work with "done" still being private, you have to capture it in the "[]" of the lambda, so either "[&done]" to capture the variable manually by reference, or "[&]" to capture everything in the current scope by reference (you can capture it by value too, but considering the semantics of your class this would be nonsensical).


That's not entirely correct. Lambda expressions are actually more like local classes and according to section 11/2 of the standard: "A local class of a member function may access the same names that the member function itself may access."

Explained here: http://stackoverflow.com/questions/12731215/access-rights-of-a-lambda-capturing-this
JonGalt
Profile Joined February 2013
Pootie too good!4331 Posts
March 08 2013 15:16 GMT
#5285
On March 07 2013 18:50 disco wrote:
Show nested quote +
On March 07 2013 15:54 JonGalt wrote:
On March 07 2013 04:57 tofucake wrote:
do you have php installed and enabled?


I have php installed. I think I have it enabled, but I am unsure now.

I installed php5, mysql, and phphmyadmin through the terminal the other day. Then I made a dbconfig.php, register.php, login.php, members.php, logout.php, and integrated them with my login.html and register.html.

When I try to register a user through register.html, my browser (chromium) just downloads register.php instead of sending the data to the database. I did many searches and it seemed like I did not have the apache2 conf files correctly configured. After editing what was suggested, I still have the same problem.

And I don't think I have Xammp installed. If you need more information or I am unclear, let me know.


Did you install libapache2-mod-php5 and not just the php cli? (If you want to run php as a apache module that is, which I am assuming you do).

Using a package manager (apt-get) makes your life so much easier. It will automatically update the configuration files for you as well.


I do have this installed. The same problem persists and is rather annoying. Any ideas or suggestions? I am searching the web and trying to read up but still nothing.
LiquidLegends StaffWho is Jon Galt?
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2013-03-08 15:38:20
March 08 2013 15:23 GMT
#5286
@heishe nevermind first reply i am stupid. and nevermind the class itself. i was trying to make it look pretty using initializer list on it's variables instead of after the constructor (which works, used that several times for active object implementation).

@memcpy yes, i tried using initializer list as well, and that worked. that was where i came from so to say. but with the lambda in it it looks so messy. same if it is within the constructor.

it seems like if i use the il on each class variable it does not get access to the private / protected members of the class, but if it follows the constructor it does.

which actually seems to be consistent with:
"A local class of a member function may access the same names that the member function itself may access."

thanks for replies.
conspired against by a confederacy of dunces.
Yoshi-
Profile Joined October 2008
Germany10227 Posts
March 08 2013 15:31 GMT
#5287
On March 09 2013 00:16 JonGalt wrote:
Show nested quote +
On March 07 2013 18:50 disco wrote:
On March 07 2013 15:54 JonGalt wrote:
On March 07 2013 04:57 tofucake wrote:
do you have php installed and enabled?


I have php installed. I think I have it enabled, but I am unsure now.

I installed php5, mysql, and phphmyadmin through the terminal the other day. Then I made a dbconfig.php, register.php, login.php, members.php, logout.php, and integrated them with my login.html and register.html.

When I try to register a user through register.html, my browser (chromium) just downloads register.php instead of sending the data to the database. I did many searches and it seemed like I did not have the apache2 conf files correctly configured. After editing what was suggested, I still have the same problem.

And I don't think I have Xammp installed. If you need more information or I am unclear, let me know.


Did you install libapache2-mod-php5 and not just the php cli? (If you want to run php as a apache module that is, which I am assuming you do).

Using a package manager (apt-get) makes your life so much easier. It will automatically update the configuration files for you as well.


I do have this installed. The same problem persists and is rather annoying. Any ideas or suggestions? I am searching the web and trying to read up but still nothing.


http://www.php.net/manual/en/install.unix.apache2.php

See if steps 7 and 8 apply to your Config file from apache.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-03-08 19:52:28
March 08 2013 19:51 GMT
#5288
Could you recommend a good and active programming forum to visit? I'm particularly interested in C++ and Java. I've come across some forum called ProgrammingForum, but I dunno if it's any good. I also know about StackOverflow, but I don't count it as a forum because it is ask-answer with no further discussion, but I may be wrong.
Frigo
Profile Joined August 2009
Hungary1023 Posts
March 09 2013 06:08 GMT
#5289
On March 05 2013 22:14 Frigo wrote:
Speaking of non-blocking I/O, does anyone know the proper way to read an object from a java.nio.channels.SocketChannel? Assuming several clients and whose requests we would like to process as fast as possible.

I've been thinking of two approaches:
- Using a cached thread pool and start a receiver thread every time we notice incoming data. Receiver thread would just read an object and pass it to a queue. Not sure if it could work, the structure of SocketChannel and Socket would prevent

- Preface each transmission with the size of the serialized object and do all object reads in 1 thread. This could potentially screw up the server if a malicious server sends large sizes and/or does not send the object.


After some research and twiddling, I settled with Apache Mina. I made a thin wrapper over it that apart from connection handling, puts the incoming messages in a LinkedBlockingQueue so I can process them in a game loop. Here and here are the sources if anyone is interested.

I recommend Apache Mina, it seemed the best of the message passing frameworks I have looked at.
http://www.fimfiction.net/user/Treasure_Chest
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
Last Edited: 2013-03-09 21:01:57
March 09 2013 21:01 GMT
#5290
What's wrong in this code?
+ Show Spoiler +



#include "Oving 6 del 7.h"
#include <iostream>
#include <time.h>

using namespace std;

void Minesweeper::getInput()
{
int height;
cout << "Height?" << endl;
cin >> height;
while (height<2)
{
cout << "Wrong, idiot, again PLEASE!" << endl;
cin >> height;
}
this->height;

int width;
cout << "Width?" << endl;
cin >> width;
while (width<2)
{
cout << "Wrong, idiot, again PLEASE!" << endl;
cin >> width;
}
this->width;

int mines;
cout << "Mines?" << endl;
cin >> mines;
while (mines<((width*height)/2))
{
cout << "Wrong, idiot, again PLEASE!" << endl;
cin >> mines;
}
this->mines;
}


void Minesweeper::makeBoard()
{
board = new int*[width];
for (int i = 0;i<width;i++)
{
board[i] = new int[height];
for (int s = 0;s<height;s++)
{
this->board[i][s] = 0;
}

}

mask = new int*[width];
for (int i = 0;i<width;i++)
{
mask[i] = new int[height];
for (int s = 0;s<height;s++)
{
this->mask[i][s] = 0;
}
}
}

void Minesweeper::placeMines()
{
int a;
while (a <= this->mines)
{
srand(time(NULL));
int wid = rand() % this->width;
int hei = rand() % this->height;
this->board[hei][wid] = -1;
if ((wid+1)<=this->width)
this->board[hei][wid+1] += 1;
if ((wid-1)<=this->width)
this->board[hei][wid-1] += 1;
if ((hei+1)<=this->height)
this->board[hei+1][wid] += 1;
if ((hei-1)<=this->width)
this->board[hei-1][wid] += 1;
a++;
}
}

void Minesweeper::setFlag(int a, int b)
{
if (this->mask[a][b] != 2)
this->mask[a][b] = 2;
else if (this->mask[a][b] == 2)
this->mask[a][b] = 0;
}

bool Minesweeper::openSquare(int a, int b)
{

if (a >= 0 and a <= this->height and b >= 0 and b <= this->width and this->mask[a][b] != 2)
if (this->mask[a][b] == -1)
return true;

return false;
this->open++;
}

void Minesweeper::printBoard(bool a)
{
{
if (true)

for (int i = 0;i<height;i++)
{
for (int s = 0;s<width;s++)
{
cout << board[i][s] << "\t";
}
cout << endl;
}
}

}


int main()
{
Minesweeper brett;
brett.getInput();
brett.makeBoard();
brett.placeMines();
brett.printBoard(true);
}




When I run it I get a red arrow that points to the int wid = rand() % this->width; in the placeMines() function. It doesn't say anything more than that.
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
Isualin
Profile Joined March 2011
Germany1903 Posts
Last Edited: 2013-03-09 21:19:39
March 09 2013 21:17 GMT
#5291
i am not really good at C but what is the purpose of "this->height;"(width etc.) after the while loop? don't you need to assign some value to them? i think you were going to use something like "this->height=height" or something like that.
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
March 09 2013 21:21 GMT
#5292
Wouldn't this->height fetch the height value?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
Isualin
Profile Joined March 2011
Germany1903 Posts
March 09 2013 21:33 GMT
#5293
this->height is a pointer to height object in the minesweeper class but does nothing just by pointing to it if i understand correctly. And don't you need to initialize brett using "new Minesweeper(x....);"?
| INnoVation | The literal god TY | ByuNjwa | LRSL when? |
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2013-03-09 21:41:38
March 09 2013 21:35 GMT
#5294
in makeBoard() you need to assign this->height to the value you retrieved from the user.
consider this:
#include <iostream>

using namespace std;

struct a{
int b {3};
void c(){
int b = 2;
cout << b << endl;
cout << this->b << endl;
this->b = b;
cout << this->b << endl;
}
};

int main(){
a an_a;
an_a.c();
}

output:
2
3
2
notice how this->b changes to 2 after getting set equal to the local variable b.

also in placeMines() you only declare the variable a but you don't initialize it to any value.
int a;
while (a <= this->mines)


edit: i'm not saying these are the only errors, i didn't look through it that closely. :>

also:

void woop_if_true(bool a){
if (true){
woop();
}
}

will always woop() no matter what value the variable bool a has. step up your game arnstein. this is not what you should be having trouble with when you are learning about classes!
conspired against by a confederacy of dunces.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
March 09 2013 21:39 GMT
#5295
On March 09 2013 00:16 memcpy wrote:
Show nested quote +
On March 08 2013 23:37 heishe wrote:
On March 08 2013 12:15 nunez wrote:
why does 'done' have to be public for this to compile?
class listener{
atomic<bool> done{false};
thread worker{
[this](){
while(!(this->done.load())){
this_thread::sleep_for(chrono::milliseconds(100));
}
}
};
public:
listener(){}
~listener(){
done.store(true);
worker.join();
}
};

testing.cpp:9:28: error: ‘std::atomic<bool> listener::done’ is private
testing.cpp:12:18: error: within this context


Lambda expressions are basically global functions, even if you create them inside the scope of a class. Global functions don't have access to the private members of any class' object, so you need to make it public. If you want it to work with "done" still being private, you have to capture it in the "[]" of the lambda, so either "[&done]" to capture the variable manually by reference, or "[&]" to capture everything in the current scope by reference (you can capture it by value too, but considering the semantics of your class this would be nonsensical).


That's not entirely correct. Lambda expressions are actually more like local classes and according to section 11/2 of the standard: "A local class of a member function may access the same names that the member function itself may access."

Explained here: http://stackoverflow.com/questions/12731215/access-rights-of-a-lambda-capturing-this


That's interesting. Thanks!
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
March 09 2013 21:44 GMT
#5296
Thanks a lot! I thought that since it was the same name of the variables, you could just do this->width
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2013-03-09 21:56:12
March 09 2013 21:54 GMT
#5297
On March 10 2013 06:44 Arnstein wrote:
Thanks a lot! I thought that since it was the same name of the variables, you could just do this->width


if you have a struct a that has some variable b, then the variables name is not b, but rather a::b.
conspired against by a confederacy of dunces.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
March 09 2013 22:00 GMT
#5298
On March 10 2013 06:54 nunez wrote:
Show nested quote +
On March 10 2013 06:44 Arnstein wrote:
Thanks a lot! I thought that since it was the same name of the variables, you could just do this->width


if you have a struct a that has some variable b, then the variables name is not b, but rather a::b.


Of course, I should have understood that. Thanks for the help! Do you study engineering/informatics? If so, where?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
nunez
Profile Blog Joined February 2011
Norway4003 Posts
March 09 2013 22:47 GMT
#5299
On March 10 2013 07:00 Arnstein wrote:
Show nested quote +
On March 10 2013 06:54 nunez wrote:
On March 10 2013 06:44 Arnstein wrote:
Thanks a lot! I thought that since it was the same name of the variables, you could just do this->width


if you have a struct a that has some variable b, then the variables name is not b, but rather a::b.


Of course, I should have understood that. Thanks for the help! Do you study engineering/informatics? If so, where?


aha, yes, you have found me out!
i study cybernetics at ntnu. you?
conspired against by a confederacy of dunces.
green.at
Profile Blog Joined January 2010
Austria1459 Posts
March 09 2013 22:57 GMT
#5300
If anyone is interested in a small programming challenge, https://www.hackerrank.com/twitch/challenges
It's a simple problem and you can write/compile code in your browser in multiple languages.
Inputting special characters into chat should no longer cause the game to crash.
Prev 1 263 264 265 266 267 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
Rongyi Cup S3 - Group D
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 186
Ketroc 81
StarCraft: Brood War
PianO 146
Shuttle 80
ZergMaN 60
Noble 20
Icarus 8
Bale 6
Dota 2
monkeys_forever476
NeuroSwarm120
febbydoto15
League of Legends
JimRising 848
Counter-Strike
taco 194
minikerr28
Super Smash Bros
hungrybox1773
Mew2King21
Heroes of the Storm
Khaldor135
Other Games
tarik_tv15544
summit1g13436
gofns11126
WinterStarcraft294
ViBE125
Organizations
Other Games
gamesdonequick1330
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH102
• Mapu17
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21618
League of Legends
• Scarra2324
Upcoming Events
RongYI Cup
6h 59m
herO vs ShoWTimE
Solar vs Classic
Wardi Open
9h 59m
Monday Night Weeklies
12h 59m
OSC
19h 59m
Replay Cast
1d 4h
RongYI Cup
1d 6h
Clem vs TriGGeR
Maru vs Creator
WardiTV Invitational
1d 9h
Replay Cast
2 days
RongYI Cup
2 days
WardiTV Invitational
2 days
[ Show More ]
The PondCast
3 days
HomeStory Cup
4 days
Korean StarCraft League
4 days
HomeStory Cup
5 days
Replay Cast
5 days
HomeStory Cup
6 days
Replay Cast
6 days
Liquipedia Results

Completed

BSL 21 Non-Korean Championship
OSC Championship Season 13
Underdog Cup #3

Ongoing

CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Acropolis #4 - TS4
Rongyi Cup S3
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025

Upcoming

Escore Tournament S1: W6
Escore Tournament S1: W7
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
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.