I have an application that uses an array of threads to call a method along with thread.join(). I was just wondering what would be the best way to handle the thread in case if one of the thread fails? Should I put a try catch block on the method that is being called or should I put the try catch block on the array of threads, or is there any other proper way to handle failed threads?
Is it possible to handle situations where static cast fails. I have a sample code written belo:
typedef struct test { int a; int b; } tester; void setevent(void *in) { tester *recv = static_cast<tester*>(in);
[Code] ....
In above code when setevent is called with the tester object, there is no issue, but if we pass random value it leads to seg fault. This is because static_cast is not type_safe, but can it be handled in any other way?
I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.
But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.
What can caused that, and How I can make it works?
SerialPortComm.cs
public partial class SerialPortComm : UserControl { public SerialPort mySerialPort = new SerialPort(); public void Open_Port(string comNumber, int baudRate) { mySerialPort.PortName = comNumber; mySerialPort.BaudRate = baudRate;
I've been thinking over this for long time... For example, when a button is clicked, print a string "clicked" after 5 seconds. (the button won't be blocked)
If a class A contains an array of objects of another class B.. And in the constructor of A, while constructing objects of B, any one object throws an exception, then how can we guarantee to release all the memory acquired.. so that there is no memory leak..
class B{}; class A{ public: B Array[100]; ... };
In the above code, if in constructor of A, suppose 99 objects of B are constructed successfully, but 100th object throws exception, then how can we guarantee to release all the memory acquired by the other 99 objects?
I have a game that I'm trying to create but I don't really know how to handle mouse motions yet. I have read the LazyFoo.net lesson 9. And I have too searched around on Google but haven't find any good article for what I want to do
But what I want is to check if the mouse is OVER the START button of the game and if the user has pressed the LEFT mouse button the game should START.
This works when I am hovering over the area there I want the mouse to do something:
Code: else if (event.type == SDL_MOUSEMOTION) { if (event.motion.x == 0) { quit = true; } }
I do not know how to check this. The START and QUIT button is in the middle of the screen and I don't know how to position the mouse there either.
I am using SDL 2.0. But I don't know how to handle mouse input. Do you think you can explain of how to do that? Or give me a link that explains that really great?
I know how to handle a mouse button that presses down for a sec.
Code: if (event.type == SDL_MOUSEBUTTONDOWN){ if (event.button.button == SDL_BUTTON_LEFT){ // Do something . . . } }
But not how to handle the mouse input of what the mouse is hovering over and that.
Like in a start menu of a game. I want a button for example to appear blue when I hover over it and when I click on it. It should start the game for example.
I have an MFC program created from the app wizard. It is an MDI program, reading/writing text files using Serialize. I can read the document and know that the entire document was read into my buffer without any errors. This was verified by compaing the number of bytes read with the file length.
How do I get the document to display in my main/child window?
How do I read the document from the window so I can save it back to the file?
As we know in C there is no checking if values passed to a function that takes enum are correct, that is if they have been defined in this enum. Example from Enums in C | Occasionally sane ([code] tags don't work on my fx 18.0.1 this is why I put in on pb): [URL] ......
Here c - How to check if an enum variable is valid? - Stack Overflow they say that common convention is add check whether value passed as the parameter is not bigger than the maximum value in enum. But how about situations when enum is composed of numbers from 1-20 and then from 500-510?
I programming currently something with OpenGL. Now I have written some wrapper classes, like Shader, Program .... All works fine, but I don't like to call Shader.GetHandle() every time I want to call a OpenGL function manually where I need the object handle/id. (GetHandle() returns the OpenGL ID of the object)
So now I wonder, is it possible to program it in C++ so, that I can put my objects to gl methods and c++ automatically pass the handle/id member to that function ? Is there maybe a operator that I can use for that?
In 2D games, what's the best way to handle the order of drawing objects? Because most games have a background, tiles to be drawn behind the player, perhaps tiles to be drawn covering up the player, etc. My point is, with my current setup of simply looping through all objects and drawing, I have no control over what objects are drawn on top of or behind the others. My best idea so far is to hold a vector of object pointers, each vector representing a different "visibility level", like so:
class Level{ //... std::vector<Object> allObjectInstances; std::vector<Object*> visibilityOne; //background objects std::vector<Object*> visibilityTwo; //objects in front of background but not necessarily all the way in front //and so on for more objects };
If I go through with this, I'm wondering how I could loop through all my objects and add them to each vector, then shorten whatever I have to loop through for subsequent visibility vectors. handling the order of drawing objects?
How to create .cpp file (new class) that will handle all the random number generators (<random> library) that main could possibly access. When I looked for a way how to implement random generators the examples were always in the main function or in a class in the main.cpp (with no header file and the generator was not seeded as I imagine it should be = only once in a program).
Questions follows after this malfunction code.
main.cpp #include "randomizer.h" int main() { Randomizer randObject(0, 10, 125); //Set bounds and seed generator int mainVar = randObject.getRandInt(); //Store newly generated random number for future work
[Code] .....
1) So I think that I should somehow declare these generators and distribution in the header file. Is it like declaring int a;?
I tried writing std::default_random_engine defGen; into the header file which only silenced compiler's errors but defGen wasn't seeded.
I have seen some examples using auto a = randInt(defGen); (or maybe with the use of auto a = std::bind.... But what does auto represent? I can't use it in the header file.
2) Can I ensure that the randObject is seeded only once? If for examle I need randObject2 with different boundMax, can I still use the same defGen which was seeded the first time? That should ensure better "randomness" through the program, shouldn't it?
3) Is there better way (and easy too) to "interface" random number generators? The class in the end should provide "get" function to acces int, double, bool, signed/unsigned... or some other specialities like random prime numbers, etc.
If it is anyhow related I am using Code::Blocks IDE with GCC compiler (4.7.1)
I'm stuck on the last part of my program. The directions are the following~
Expand the program to add an overloaded function to handle floating point numbers (i.e., doubles). Include output for one list of integers and one list of doubles. Use this function prototype: double avgx(double&, double&, int, ...);
Compile and run. You should have one function named avg, one named davg, and two functions named avgx
My code does not compile and I think I'm not declaring my function prototype correctly?
#include <iostream> using std::cout; using std::endl; #include <cstdarg> // function prototype(s) int avg(int, ...);
I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.
Code:
#include <stdio.h> #include <string.h> char tracks[][80] = { "I left my Heart at Harvard Medical School", "Newark, Newark, You suck balls", "Dancing with a dork", "From Here to maternity", "The Girl from Iwo Jima",