Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 25 26 [27] 28 29 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95914 times)

winner

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #390 on: October 07, 2010, 11:22:54 pm »

I have a question why doesn't this work?
Code: [Select]
using namespace std;
struct foo{
virtual int baz (int a) {
return a;
}
};
struct bar: foo{
int baz () {
return baz(1);
}
};
int main(){}
when this does
Code: [Select]
using namespace std;
struct foo{
virtual int baz (int a) {
return a;
}
};
struct bar: foo{
int baz (int a) {
return a;
}
int baz () {
return baz(1);
}
};
int main(){}
Logged
The great game of Warlocks!

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #391 on: October 08, 2010, 05:40:12 pm »

That could be several problems. The error messages are helpful.
Logged

Dasleah

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #392 on: October 08, 2010, 05:48:11 pm »

At first I was like :o for seeing HTML / CSS in a programming thread, and then I saw all the <tr> and <td>s and now I'm just
Logged
Pokethulhu Orange: UPDATE 25
The Roguelike Development Megathread.

As well, all the posts i've seen you make are flame posts, barely if at all constructive.

winner

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #393 on: October 08, 2010, 05:51:47 pm »

for the first one
Code: [Select]
test.cpp: In member function ‘int bar::baz()’:
test.cpp:9: error: no matching function for call to ‘bar::baz(int)’
test.cpp:8: note: candidates are: int bar::baz()
and the second compiles fine

I can get around it by just renaming the first function but I don't understand what the problem is because I thought that functions were identified by their arguments.
« Last Edit: October 08, 2010, 06:00:06 pm by winner »
Logged
The great game of Warlocks!

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #394 on: October 08, 2010, 05:59:58 pm »

compiler error

Code: [Select]
using namespace std;
struct foo{
virtual int baz (int a) {
return a;
}
};
struct bar: foo{
int baz () {
return baz(1);
}
};
int main(){}

So if you change the
Code: [Select]
int baz () {
return baz(1);
}
into
Code: [Select]
int WWW (){
return baz(1);
}
It compiles fine?

Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #395 on: October 08, 2010, 06:17:57 pm »

What's happening is called "Name Hiding". http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9 provides a good example of what is happening, why it is happening, and how to fix it.
« Last Edit: October 08, 2010, 06:24:51 pm by Normandy »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #396 on: October 10, 2010, 09:57:21 pm »

I'm currently making a small project with C++ and directX. I want to get input (or more specifically, which keys are pressed) in order to store said keys in a string; essentially text-editor functionality. Is there an easy way of doing this, or will I need several hundred 'if' statements using my normal direct input method of getting keypresses?
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #397 on: October 11, 2010, 08:38:49 am »

First, a switch would be far better than a hundrred ifs.

Second, what sort of input do you have now? There is a win32 function that can convert scancodes to letters.
Logged
Eh?
Eh!

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #398 on: October 11, 2010, 11:30:32 am »

I currently use the Direct Input code more or less unmodified from Frank D Luna's book "Introduction to 3D Game Programming With DirectX 9.0c, A Shader Approach"
As follows:
Spoiler (click to show/hide)
With keyDown(char key); taking DIK key codes

How does one go about it in win32?
« Last Edit: October 11, 2010, 11:48:30 am by alway »
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #399 on: October 11, 2010, 05:24:00 pm »

That looks practically the same, for checking if a key is pressed. However, decoding keys as they are pressed in win32 is like this(At least the way I do it, in C):
Spoiler (click to show/hide)

I don't know if directX lets you respond to window messages, but responding to them is the proper way to read input in the order it is pressed, unless you have something that does it for you.
Logged
Eh?
Eh!

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #400 on: October 11, 2010, 06:09:55 pm »

Awesome, thanks!

My program actually runs the directX on a window created with win32, so it shouldn't take too much effort to make it work now that I know what to put in the switch statement. :D
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #401 on: October 11, 2010, 06:17:19 pm »

When the if() fails, it means that it is a non-ASCII key, like VK_LEFT or whatever the one for shift or control is, so having an else to handle such cases is a good idea if you use them.
Logged
Eh?
Eh!

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #402 on: October 16, 2010, 09:15:05 am »

I'm doing a breadth-first search for a path between nodes A and B.

The ultimate goal is to end up with a path list (vector) that starts at node A and leads to node B.
So an example of a desired result would be { A, H, I, J, K, B } , where HIJK are connecting nodes.

With breadth first, the only way I can think of to keep track of the path a node is part of
 is to have each node store the ENTIRE path leading up to it, and copy it to new nodes.

Any alternate solutions?

I would prefer to not use an alternate method of path finding.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #403 on: October 16, 2010, 09:44:37 am »

You could use a form of linked list. Each node having links to the next nodes in each path and a link backwards to the previous node in the chain for ease of finding the final path. Thus giving you a data structure which literally looks like the diagram from the 'breadth first search' page on wikipedia. http://en.wikipedia.org/wiki/File:Breadth-first-tree.svg
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #404 on: October 16, 2010, 10:04:30 am »

I don't quite follow.

The object being searched is already a tree.
That does give me an idea though, which is probably what you meant.

I'll just have each node remember a temporary pointer to the node it came from,
 then the path can be followed back once it has been found.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream
Pages: 1 ... 25 26 [27] 28 29 ... 78