[QUOTE=TommySprat;31675033]Sometimes I see numbers like 10.f or 1,5f. usually as parameters. My guess is that's it's some short kind of way of passing it explicitly as a float but I have not found any written confirmation of that anywhere (it's still just a guess to me).[/QUOTE]
Floating-point constants are double by default, you are correct.
[QUOTE=TommySprat;31675033]
My second problem involves dynamic memory. I want to create an array of dynamic memory that will hold an indefinite amount of elements. I don't mean infinite, I just want to "stack" stuff in there. It seems that is impossible and the only way to achieve the same result is to recreate the array every time except with one element extra and deleting the old one. I have no problems with implementing that if i have to but if there's a more natural way I'd like to know.[/QUOTE]
You can resize allocated memory, I believe. However, you might want to use a [url=http://www.cplusplus.com/reference/stl/]standard container[/url] for this.
[editline]12th August 2011[/editline]
:ninja: donut
[QUOTE=esalaka;31675133]Huh, threaded binary trees actually look pretty damn useful. Simple iterative traversal? YES PLEASE.[/QUOTE]
I'm pretty sure I actually used one of these somewhere.
[editline]11th August 2011[/editline]
Yep, here it is:
[url]https://github.com/ml32/Morse-Code-Virtual-Keyboard/blob/master/morsetree.c[/url]
Aren't binary trees relatively fast for lookup purposes, for that matter?
I'm using linked lists mostly out of laziness and, well, fuck them.
[editline]12th August 2011[/editline]
Well, balanced binary trees anyway. No idea of how to make them self-balancing tho'
[QUOTE=esalaka;31675269]Aren't binary trees relatively fast for lookup purposes, for that matter?
I'm using linked lists mostly out of laziness and, well, fuck them.
[editline]12th August 2011[/editline]
Well, balanced binary trees anyway. No idea of how to make them self-balancing tho'[/QUOTE]
Yeah they're much faster for large data sets.
As for self-balancing, I think I've implemented an AVL tree before and I remember it being a huge pain. I think red-black trees make a little more sense.
[QUOTE=NovembrDobby;31669804]If it's just squares, you can use bounding rectangles for all of them. Before you move an object, check its future position (current pos + velocity or whatever) for intersections between other objects, and if it doesn't collide it's ok to move it. It's normally easier to prevent collisions in advance instead of fixing them after they happen.
Also, if your objects are moving at any decent speed, you may need to do something to avoid tunnelling. This is where they move fast enough to pass through each other because the simulation never detects that they were touching.[/QUOTE]
Never thought about using velocity, might fix the bugginess thanks.
-snip- my bad.
Well, I have a bit of a stupid problem.
This actually has to do with the "Hello World!" exercise, and something isn't right.
I was told to type this:
[CODE]// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}[/CODE]
After typing and all of that, it simply flashes on screen for what seems like a millisecond.
I learned that when I rewrite it as such, with cin.get() replacing return 0:
[CODE]// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
cin.get();
}[/CODE]
It works fine, and waits for me to press Enter.
Why is this? In every book and PDF that I'm reading, they're all saying that you just need to use return 0. I'm using Visual C++ 2010 Express, by the way. I keep coming back to this, and I'm not advancing in C++ because I don't understand why this is. I also don't see the point of endl, if you can just leave it blank and the same thing will happen.
[QUOTE=Grabigel;31681286]Well, I have a bit of a stupid problem.
This actually has to do with the "Hello World!" exercise, and something isn't right.
I was told to type this:
[CODE]// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}[/CODE]
When I do, it simply flashes on screen for what seems like a millisecond.
I learned that when I rewrite it as such, with cin.get() replacing return 0:
[CODE]// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
cin.get();
}[/CODE]
It works fine, and waits for me to press Enter.
Why is this? In every book and PDF that I'm reading, they're all saying that you just need to use return 0. I'm using Visual C++ 2010 Express, by the way. I keep coming back to this, and I'm not advancing in C++ because I don't understand why this is.[/QUOTE]
I'm fairly new to using visual studio and programming in general but i know this much.
They say you don't need the cin because when you run it with the debugger it usually stops it at the end.
Try using cntrl + F5 to run your program that should stop it.
Just bear in mind when you run just the .exe file it will not stop at the end of the program.
[QUOTE=Grabigel;31681286]I learned that when I rewrite it as such, with cin.get() replacing return 0:
[CODE]// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
cin.get();
}[/CODE]
It works fine, and waits for me to press Enter.
Why is this? In every book and PDF that I'm reading, they're all saying that you just need to use return 0. I'm using Visual C++ 2010 Express, by the way. I keep coming back to this, and I'm not advancing in C++ because I don't understand why this is. I also don't see the point of endl, if you can just leave it blank and the same thing will happen.[/QUOTE]
You don't replace [i]return 0;[/i] with [i]cin.get();[/i], you simply put [i]cin.get();[/i] right after outputting the text. As soon as the program finished the console is no longer necessary, that's why it disappears. Another way to run your program is to run it with Ctrl-F5, which inserts a pause automatically.
[QUOTE=Overv;31681411]You don't replace [i]return 0;[/i] with [i]cin.get();[/i], you simply put [i]cin.get();[/i] right after outputting the text. As soon as the program finished the console is no longer necessary, that's why it disappears. Another way to run your program is to run it with Ctrl-F5, which inserts a pause automatically.[/QUOTE]
So, more like this?:
[CODE]
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
cin.get();
return 0;
}[/CODE]
Why do you need to use ctrl+F5? Why does it insert a pause? Is it for this reason?
I have a lot of stupid questions, because I don't understand all of it. :(
[QUOTE=Grabigel;31681428]So, more like this?:
[CODE]
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
cin.get();
return 0;
}[/CODE]
Why do you need to use ctrl+F5? Why does it insert a pause? Is it for this reason?
I have a lot of stupid questions, because I don't understand all of it. :([/QUOTE]
I never really thought about it, I think its a convenience thing.
If you get into more advanced debugging you can make the program stop at certain points to check values etc.
Working on my first C# program in a while, and I've run into an issue. I want to print this text to the richtextbox when the program starts, and to keep printing it for as long as the input = null. What am I doing wrong?
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string text = null;
public Form1()
{
InitializeComponent();
}
private void mainclass(object sender, EventArgs e)
{
do
{
textBox1.Text = "Oh, hello there! I didn't see you walk in. Please, make yourself at home.";
}
while (text != "null");
}
private void button1_Click(object sender, EventArgs e)
{
//text = (new Uri(textBox1.Text.ToString));
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
[/code]
Additionally, how would I get the input from the textbox and save it to a variable?
I have a class and an external class pointer.
I can cast between them implicitly both ways (My class just has that class pointer as member).
Now I want to do something like this:
[cpp]
CMine m;
CExternal e;
m = e; // possible, e = m would be too
void SomeExternalFunc(void(*f)(CExternal));
void MyFunction(CMine);
SomeExternalFunc(MyFunction); // :([/cpp]
If I just cast it like (void(*)(CExternal))MyFunction I can pass it, but it causes a segfault, I guess because my class is not cast properly.
[editline]12th August 2011[/editline]
Oh forget it, I fucked up.
[editline]12th August 2011[/editline]
Or, don't. I found an error, but it still doesn't cast properly.
[editline]12th August 2011[/editline]
If C++0x wasn't a bitch and would let me pass a lambda function capturing a reference as pointer, I would easily be able to work around that and it wouldn't even look ugly.
A reference as pointer? Nope.
Anyways, the solution is actually easy:
[cpp]void MyFunction(CExternal ext)
{
CMine mine = ext;
//do stuff with mine
}[/cpp]
[QUOTE=ZeekyHBomb;31685808]A reference as pointer? Nope.
Anyways, the solution is actually easy:
[cpp]void MyFunction(CExternal ext)
{
CMine mine = ext;
//do stuff with mine
}[/cpp][/QUOTE]
Now my problem is that I have stuff in my constructor/destructor and if I do it like this, it reinitializes and then closes my Lua environment.
That was my problem at first, that I didn't pass a reference.
I guess I'll need to write separate init and destruct functions, if I want this to work. :/
[editline]12th August 2011[/editline]
And I already figured out your solution, but it'd be nice to do it without ever needing to see lua_State* again.
Anyone know a good place that explains the Minimax algorithm in a simple way? I want to implement a perfect Tic Tac Toe AI using it, but the Wikipedia page on it is a bit complicated (and a bit too theoretic) for me.
[QUOTE=WeltEnSTurm;31685856]Now my problem is that I have stuff in my constructor/destructor and if I do it like this, it reinitializes and then closes my Lua environment.
That was my problem at first, that I didn't pass a reference.
I guess I'll need to write separate init and destruct functions, if I want this to work. :/
[editline]12th August 2011[/editline]
And I already figured out your solution, but it'd be nice to do it without ever needing to see lua_State* again.[/QUOTE]
What's wrong with passing a reference then?
[QUOTE=ZeekyHBomb;31687437]What's wrong with passing a reference then?[/QUOTE]
Because I can't pass a function to that external function which takes my class as argument, it has to be lua_State*.
Taking ownership of memory you didn't allocate is usually evil if you can't control how it will be handled.
A possible solution would be passing a destruction-functor for the memory as (template-)parameter to your class, like what the STL smart pointers do iirc. Then you could, for this specific instance, just pass an empty destruction-functor to your class and the lua_State* will be left intact.
Im doing this to try and limit the frame rate
[cpp]if(Window::frameTime < Window::requestedFrameTime)
{
Sleep(Window::requestedFrameTime - Window::frameTime);
}
Window::frameTime = clock.getElapsedTime();
clock.reset();[/cpp]
but it only works on every other frame
[QUOTE=Richy19;31689221]Im doing this to try and limit the frame rate
[cpp]if(Window::frameTime < Window::requestedFrameTime)
{
Sleep(Window::requestedFrameTime - Window::frameTime);
}
Window::frameTime = clock.getElapsedTime();
clock.reset();[/cpp]
but it only works on every other frame[/QUOTE]
That looks like SFML. If so, use SetFramerateLimit. If I am mistaken and the your library does not provide such functionality, just put Window::frameTime = clock.getElapsedTime(); above the if-statement.
[editline]12th August 2011[/editline]
You might also want to account for sleeping too long.
[QUOTE=ROBO_DONUT;31674856][i]O(n)[/i] memory complexity for [i]iteration[/i]?
Shouldn't it be like [i]O(log n)[/i]?
Your stack only needs to be as large as the tree is deep, and any reasonable tree should be around [i]log n[/i].
Unless I've misunderstood.
[editline]11th August 2011[/editline]
You could make some kind of ridiculous [url=http://en.wikipedia.org/wiki/Threaded_binary_tree]threaded[/url] octree :v:[/QUOTE]
Oh, that's true. The stack shouldn't grow much larger than O(log n). I was just thinking that if every node referenced its parent, it'd be simple enough to iterate, and that'd mean an increase of n pointers.
[QUOTE=ZeekyHBomb;31689702]That looks like SFML. If so, use SetFramerateLimit. If I am mistaken and the your library does not provide such functionality, just put Window::frameTime = clock.getElapsedTime(); above the if-statement.
[editline]12th August 2011[/editline]
You might also want to account for sleeping too long.[/QUOTE]
Yea its not SFML im making my own :D I have just taken inspiration in SFML :P
I ended up doing it like this:
[cpp]
int remainingTime = Window::requestedFrameTime - clock.getElapsedTime();
if (remainingTime > 0)
Sleep(remainingTime);
Window::frameTime = clock.getElapsedTime();
clock.reset();
[/cpp]
Trying to compile my Directx C++ in release mode but I'm getting errors. I've added the directx directory's to the release mode but im getting different errrors.
[IMG]http://i967.photobucket.com/albums/ae154/chrismelling/Errors.png[/IMG]
[QUOTE=Jimmylaw;31698108]Trying to compile my Directx C++ in release mode but I'm getting errors. I've added the directx directory's to the release mode but im getting different errrors.
[IMG]http://i967.photobucket.com/albums/ae154/chrismelling/Errors.png[/IMG][/QUOTE]
For some reason you're not linking against user32.lib.
Worked, thanks.
[QUOTE=thf;31511084]Should be pretty simple. Just store the number they input and then do something like this:
[cpp]
int sign = 1;
float result = 0;
for (int i = 0; i < numIterations; i++) {
result += sign * 1.0 / (i * 2 + 1);
sign = -sign;
}
result *= 4;
[/cpp]
Where numIterations is the number of iterations they inputted.[/QUOTE]
Sorry for the late reply but thanks. I did it on my own and I did the same exact loop as you except I my line 5 was:
[code]
int sign = 1;
double result = 0;
for (int i = 0; i < iterations; i++) {
result += sign * 1.0 / (i * 2 + 1);
sign *= -1;
}
System.out.println("The Approximation is " + (result * 4));
[/code]
Didn't get up to floats in my textbook yet... so I don't know why you used it. All I know is that they're something like doubles haha.
[QUOTE=W00tbeer1;31698342]Sorry for the late reply but thanks. I did it on my own and I did the same exact loop as you except I my line 5 was:
[code]
int sign = 1;
double result = 0;
for (int i = 0; i < iterations; i++) {
result += sign * 1.0 / (i * 2 + 1);
sign *= -1;
}
System.out.println("The Approximation is " + (result * 4));
[/code]
Didn't get up to floats in my textbook yet... so I don't know why you used it. All I know is that they're something like doubles haha.[/QUOTE]
Same thing as doubles, though they have a bit worse precision, but I just figured for a more precise answer you'd definitely want a double.
I've just started writing some C++ code, I have almost 2 years of C# experience at this point. I was trying to chain constructors, and I figured out that it's not possible. I did, however, read that using optional arguments would be the fix in my case.
From all the examples I've seen online, they all use native types for the optional arguments (int, char, etc.). What would you set the default argument to for a class that you're passing in? For example, I want to pass in a Vector3 with the position (0, 0, 0).
[cpp]class MyClass
{
public:
MyClass(Vector3 position=???, float angle=0.0f);
}[/cpp]
[QUOTE=robmaister12;31707147]I've just started writing some C++ code, I have almost 2 years of C# experience at this point. I was trying to chain constructors, and I figured out that it's not possible. I did, however, read that using optional arguments would be the fix in my case.
From all the examples I've seen online, they all use native types for the optional arguments (int, char, etc.). What would you set the default argument to for a class that you're passing in? For example, I want to pass in a Vector3 with the position (0, 0, 0).
[cpp]class MyClass
{
public:
MyClass(Vector3 position=???, float angle=0.0f);
}[/cpp][/QUOTE]
I think you can do something like:
[cpp]class MyClass
{
public:
MyClass(Vector3 position=Vector3(0, 0, 0), float angle=0.0f);
}[/cpp]
Also you forgot the ; at the end of the class declaration.
Sorry, you need to Log In to post a reply to this thread.