I'm well educated in the C++ programming language regarding syntax, STL, etc. I haven't done any true projects with it yet other than some college courses. My goal is to start writing progams but attempt to keep it to industry best practices. One of my main goals is to work in the game industry. A door is opening which lead me to ask the...
I'm using extern to fetch variables from another class, and it works fine for int's, float's etc...
But this doesn't work, and I don't know how to do it:
Class1.cpp
struct MyStruct {
int x;
}
MyStruct theVar;
Class2.cpp
extern MyStruct theVar;
void test() {
int t = theVar.x;
}
It doesn't work because Class2 doesn't know what ...
I have a class with the only constructor like this:
IntroScreen::IntroScreen(Game *game) :
View(game), counter(0.0f), message(-1), continueAlpha(255),
continueVisible(false), screenAlpha(255), fadeIn(false), fadeOut(false)
{
}
And somewhere in a method I have this if-statement
if (counter > 10.0f)
And Valgrind says for that...
I'm using the C++ STL API to Berkeley DB 4.8, and I'm able to use bulk retrieval for a db_map or db_multimap const iterator created using begin(), but not one created from find() (or lower_bound() for multimaps).
I appreciate for single item random access uses of find() would be a waste to use bulk retrieval, but I want to access many r...
Are the members of a structure packed in C/C++? (by packed I mean that they are compact and among the fields there isn't a memory spaces)
...
suppose I have a file alpha.h:
class Alpha {
public:
template<typename T> void foo();
};
template<> void Alpha::foo<int>() {}
template<> void Alpha::foo<float>() {}
If I include alpha.h in more than one cpp file and compile with GCC 4.4, it complains there are multiple definitions of foo<int> and foo<float> across multiple object...
Hi Stackoverflow,
I have a function from an external source that returns an array of 2 uint16_t elements (which I cast to int).
I have already been able to cast these to one "big" int ((i1 << 16) + i2)
Now I need to be able to cast this to float, keeping the point value as is in memory.
Can anyone suggest a way or point me in the rig...
For a hw assignment, we are to code a reduce routine that looks like:
int reduce(long array[], int size)
//Where array is the array to reduce, and size is the size of the array.
Using STL. My initial thoughts were to create a set, put all items in the set with a comparison, but then I realized that the set I would create would never...
class PevSearch
{
boost::shared_ptr<FilterProvider> filterProvider;
public:
void RegisterFilter(const boost::shared_ptr<FilterProvider>& toRegister)
{
filterProvider = toRegister;
}
const boost::shared_ptr<const FilterProvider>& GetFilter() const
{
return filterProvider; // Compiler reports "Return...
I am trying to get unicode working on windows in a visual studio 2k8 project, and I am not sure why I can't get my project to work. My machine has all the Eastern language support installed. I went to properties->project defaults->character set: and it is set to "Use Unicode Character Set". Here is my test code:
#include <stdio.h>
#incl...
Hi all,
I am new to C++. What does it mean exactly to "new" a collection? For example:
UnicodeStringList* tmp = new UnicodeStringList;
// where UnicodeStringList is typedef to std::list<UnicodeString>
When you "new" something you have to know exactly how big you need it to be, right? So when I
use the assignment constructor to c...
When trying to monitor a directory using inotify on Linux, as we know, we get notified as soon as the file gets created (before the other process finish writing to it)
Is there an effective way to make sure that the file is not read before writing to it is complete by the other process?
We could potentially add a delayed read; but as w...
I don't understand why this code
#include <iostream>
using namespace std;
int main(){
int result=0;
_asm{
mov eax,3;
MUL eax,3;
mov result,eax;
}
cout<<result<<endl;
return 0;
}
shows the following error.
1>c:\users\david\documents\visual studio 2010\projects\assembler_instructions\ass...
I'm quite new to programming "larger" applications. I have now written a command line application with a few thousand lines of code in Visual C++ 2010, which compiles and works fine. Most of the code is C-compliant (I think), however, I found it useful to use some C++ constructs here and there. E.g., sometimes I used new/delete instead o...
I am using Qt Creator 1.3.0 with Qt 4.6.0 (32 bit) under Windows 7 Ultimate. Consider the following QThread:
Header
class ResultThread : public QThread
{
Q_OBJECT
QString _post_data;
QNetworkAccessManager _net_acc_mgr;
signals:
void onFinished(QNetworkReply* net_reply);
private slots:
void onReplyFinished(QNetworkRep...
Hi there.
I'm working on an application with statistic analysis, and I need some help.
Given a set of n points, how can I approximate a line by them. I'm sure there is an algorithm but I couldn't find it.
Thanks!
...
I know I can set a custom allocator for vectors using the syntax vector<T, Alloc>. Is there a way I can do the same for strings?
...
Hi,
I am trying to find leaks in my program, which is a framework based on Ogre3D. I am using the following defines in my code to 'new' anything so that later on any leak can be detected and reported correctly by the program.
#ifdef _DEBUG
#include <crtdbg.h>
#define MyFW_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
#define MyFW_...
hello.
I have run into broken compiler, which does not allow exceptions to inherit from std::exception (nvcc 3.0).
so had to create workaround:
struct exception {
explicit exception(const char* message) {
what_ = message;
}
virtual const char *what() const throw() { return what_; }
operator std::exception() con...
I'm having an issue with a rather intricate interaction of C++ and Python that I'm hoping the community can help me with. If my explanation doesn't make sense, let me know in the comments and I'll try to clarify.
Our C++ code base contains a parent classes called "IODevice" which is a parent to other classes such as "File" and "Socket"...