I'm doing something that seems like it could be improved, but I don't have sufficient skill to improve it. Can you help?
Given:
vector<Base*> stuff;
const vector<MetaData>& metaDataContainer = Config.getMetaData();
for(vector<MetaData>::const_iterator i = metaDataContainer.begin(), end = metaDataContainer.end(); i != end; ++i)
{
Bas...
I have a server application that opens a socket and listen for a connection. In the application, I have a separate thread that creates a socket, binds it and calls the listen and accept functions on it.
When the application closes I call closesocket on the socket that was created, then wait for the socket thread to close. However, if...
After learning more about classes and pointers, I refactored a program I had and wiped out > 200 lines of code, in the process creating two other classes, Location and Piece. The problem is, after getting everything to compile, the linker complains that the constructor for Piece is defined multiple times, with a load of errors:
In funct...
I have these template functions for use inline on device with cuda
template <class T> __device__ inline T& cmin(T&a,T&b){return (a<b)?(a):(b);};
template <class T> __device__ inline T& cmax(T&a,T&b){return (a>b)?(a):(b);};
In the code I have
cmin(z[i],y[j])-cmax(x[i],z[j])
for int arrays x,y,and z. I get the error:
error: no ...
One of the great joys of windows programming is remembering to put 'wb' or 'rb' or ios::binary in all the file open calls so that Windows doesn't merrily convert all your 0x13s.
I just had to convert a bunch of nicely standard code to use Createfile() to get a certain flag - and it occurred to me that there is no way to specify binary.
...
Hi,
My program tries to load some dlls. The problem doesn't come during the first load. But it comes every 7th time. I guess there is memory corruption. Is there a tool or something to debug the memory corruption for visual c++. I tried some memory leak tools but there is no memory leaks.
please help!!!
regards,
Suresh
...
I've seen my colleague do the second snippet quite often. Why is this? I've tried adding print statements to track the ctors and dtors, but both seem identical.
std::vector<ClassTest> vecClass1;
ClassTest ct1;
ct1.blah = blah // set some stuff
...
vecClass1.push_back(ct1);
std::vector<ClassTest> vecClass2;
...
Edit:
So this question was misinterpreted to such a ludicrous degree that it has no point anymore. I don't know how, since the question that I actually asked was whether my specific implementation of thisyes, known to be pointless, yes, not remotely resembling idiomatic C++macro was as good as it could be, and whether it necessarily had...
I am a C++ programmer currently trying to work on Java. Working on C++ I have an habit of keeping track of dynamic memory allocations and employing various techniques like RAII to avoid memory leak. Java as we know provides a Garbage Collector(GC) to take care of memory leaks.So while programing in Java should one just let go all the who...
Hi,
I overloaded the << operator of a class. How do I have to overload the operator if I want to use it on pointers, like the following?
class A {
std::string operator<<(std::string&);
}
aInst << "This works";
aPointer << "This doesnt work";
aPointer->operator<<("Whereas this works but is useless");
I hope you can help me.
hein...
I'm totally new to MFC. In fact I haven't even written anything in it yet.
I'm looking for a control similar to the one found here: http://sourceforge.net/dbimage.php?id=48455
"Toolbox", left hand side.
The CMFCOutlookBar is somewhat close but the images are quite large and the text appears beneath the icon, not beside it. Looking a...
I am working on a project where a partner provides a service as socket server. And I write client sockets to communicate with it. The communication is two way: I send a request to server and then receive a response from server.
The problem is that I send the data to the server but apparently the server cannot receive the data.
From my ...
I am new to C++, I am actually learning and in the experimentation part, however, while experimenting I ran into an issue with the cout function. The program fails when compiling. I was wondering if you guys could assist me: Here is the source I wrote.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
signed sh...
I was upgrading the OS on one of our build from Centos 5.3 32bit to Centos 5.5 32bit. After doing the package update I rebooted, checked out a clean copy of the source, built and ran the unit tests. All unit tests which rely on our MemMap base class began to fail.
The crash occurs when we attempt to set the value of the guard page aft...
I would like to split a string along whitespaces, and I know that the tokens
represent valid integers. I would like to transform the tokens into integers
and populate a vector with them.
I could use boost::split, make a vector of token strings, then use std::transform.
What is your solution? Using boost is acceptable.
...
After a break from the language, I'm about to start a new C++ project (OpenGL). My last experience with C++ has been painful partly due to using a wrong subset of its features.
I could go out and discover the "good parts" of C++ the hard way, through experience, but I'd much rather follow a style guide such as this one from Google: http...
I was trying to write a templatized quicksort function. The thought in my head was that I would write a quicksort that can operate on any data structure that has a subscript operator and an order relation on the objects contained within it, so I could do things like
quicksort<deque<int> >();
quicksort<vector<string> >();
etc.
I star...
This might be a silly question, but here goes :
I hashed a dictionary of words into an unordered_set based hash-table. My hash function was made intentionally "bad", in that all strings that contained the same set of letters would hash to the same value. I initially tried to over-ride the normal hash function behaviour, and use a "freq...
I have a class CField and a class CBoard containing a 2d array of CField.
When I do this:
board(0,0)->Is (CField::CHECK)
I get a segfault in Is() method. GDB points me right after the &, so I think it's related to it. What's the cause?
Full code:
http://pastebin.com/vetShYsL - header
http://pastebin.com/pGNPpa8N - source
...
Is there anything wrong with a union having one or more methods? Or anything to watch out for? (I can see constructors/destructors being problematic for schizophrenic reasons)
...