- Viewing Profile: Reputation: brx
Community Stats
- Group Members
- Active Posts 111
- Profile Views 1,672
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
User Tools
Contacts
brx hasn't added any contacts yet.
#4956253 Pointer to class type?
Posted by brx
on 06 July 2012 - 02:15 AM
What problem are you trying to solve with this? Looks to me like you want to implement some kind of factory pattern with this?!
#4955580 visual studio code optimization is breaking my code.
Posted by brx
on 04 July 2012 - 03:54 AM
Less error prone is the usage of std::async and std::future, however, from what you wrote so far your use-case seems to fall out of the scope of those two.
#4917705 Replace part of string in C++
Posted by brx
on 29 February 2012 - 05:52 AM
You get the first line. It contains /NAME/ and your code correctly replaces it and gives the desired output.
Now the next line is read. From what you posted it is an empty line. So your call to
line.find("/N")
will return string::npos. Same for
line.find("E/")
which is then passed to replace and causes the access out of bounds. Check the return values of your find calls and do not call replace if one of them is equal to string::npos.
#4913019 Qt in Visual Studio 2010 messes up other libs
Posted by brx
on 14 February 2012 - 11:03 AM
#4902277 c++ : Deleting object (not just its pointer) from vector
Posted by brx
on 13 January 2012 - 03:18 AM
Do not call destructors explicitly except when you REALLY know what you are doing. Read this: http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.5EDIT:
I have modified all the code with vector.push_back like this:Particle a(xx, yy, 6); v_particles.push_back(a); a.~Particle();
#4902271 c++ : Deleting object (not just its pointer) from vector
Posted by brx
on 13 January 2012 - 03:03 AM
Particle a(xx, yy, 6); // creates a new Particle object on the STACK v_particles.push_back(a); // creates a new Particle object inside push_back and uses the copy constructor of Particle to do so.
In order to find memory leaks you should look into tools that do that for you, e.g. valgrind.
#4899516 passing variable to multiple classes c++
Posted by brx
on 04 January 2012 - 02:51 AM
One thing I forgot to mention are that there are different ways of passing arguments in C++. I recommend you look up "pass by value/reference/pointer". In the example I wrote the Player object is passed by reference (noted by the '&').
#4899275 passing variable to multiple classes c++
Posted by brx
on 03 January 2012 - 09:52 AM
As you did not post any code, I assume you are doing something like this (very very simplified, but I hope you'll get the picture):
// main
int main(int argc, char** argv) {
Player p;
p.SetXPosition(5);
int playerX = p.GetXPosition(); // returns 5
// more code. ...
}
// somewhere in your Bullet class
void Bullet::someMethod() {
Player p; // creates a new instance of the class Player totally unrelated to the one created in your main method
int playerX = p.GetXPosition(); // returns the default value for x (apparently 0)
// more code ....
}
So what you need to pass to the method in Bullet that is supposed to use the Player object is the actual instance of the Player class. E.g.:
void Bullet::someMethod(Player& p) {
int playerX = p.GetXPosition(); // returns whatever the player's x position was set to outside
// more code...
}
Going back to your main function it may look like this:
// main
int main(int argc, char** argv) {
Player p;
p.SetXPosition(5);
Bullet b;
b.someMethod(p); // will use the Player object with X position set to 5
}
#4895769 [C++] Are compilers allowed to optimize ...
Posted by brx
on 20 December 2011 - 10:40 AM
Just to be sure: do a little test project where you force a number to be nan (e.g. sqrt(-1) should produce nan, I think). Apply your nan check and have different output based on the result. Compile with full optimization and check the results.
#4837840 Too many thread instances [Java]
Posted by brx
on 20 July 2011 - 02:05 AM
Example:
class Pathfinder implements Runnable {
@Override
public run() {
// pathfinding stuff
}
}
// A simple ThreadFactory class (note that it will only be used when no more threads are available:
public class SimpleThreadFactory implements java.util.concurrent.ThreadFactory {
@Override
public Thread newThread(Runnable r) {
return new Thread(r);
}
}
// initializing the thread pool (the executor):
ExecutorService mThreadPool = Executors.newFixedThreadPool(mThreadPoolSize, new FSshThreadFactory());
// starting a new pathfinder:
Pathfinder pf = new Pathfinder();
mThreadPool.execute(pf);
#4805881 Cross referencing headers?
Posted by brx
on 03 May 2011 - 05:34 AM
In your code, the SphereClass header does not need the full definition of SceneClass since you only use pointers to SceneClass. Just replace the line
#include "SceneClass.h"with
class SceneClass;
and move the include to the cpp file and you should be fine.
Note that in your case it would not work the other way around, because the SceneClass header actually uses the SphereInfoStruct as a template parameter of the vector.
#4786494 Embedding output console into VS2010
Posted by brx
on 16 March 2011 - 07:15 AM
Another way would be to use OutputDebugStr() for all your output.
#4774223 Using MSVC++ compiler from command line
Posted by brx
on 14 February 2011 - 01:52 PM
EDIT:
No, but I gave in and opened up the IDE as edd mentioned and got a command prompt that was configured correctly. I tried a dir /s *.bat from \program files\microsoft visual studio 10.0 but haven't found anything so I assume they want people to start using the IDE. Give me a command line or give me death.
Actually, you didn't even need to open the IDE which is also not what edd said. Go to start menu->All programs->Microsoft Visual Studio 2010->Visual Studio Tools. Now chose the command prompt you'd like (x86/amd64/itanium). This is, of course, only a link to the .bat file I mentioned before.
#4766077 [C++] C2664 but my Inheritance heirarchy is alright?
Posted by brx
on 28 January 2011 - 02:31 AM
- Home
- » Viewing Profile: Reputation: brx

Find content