I have a function that looks like this:
// Fetch 1 MB of data
void GetData(std::vector<char> & outData);
The 1MB is exaggerated, but I just want to make the point that it's preferable to avoid unnecessary copies.
If I add this overload:
std::vector<char> GetData()
{
std::vector<char> result;
GetData(result);
return resul...
Hello,
I have a file with thousands of lines, each one representing a point of a line. The number of chars on each line is variable. Im plotting these lines, but i only want to plot every tenth line. I know i could just do something like:
for (int k = 0; k < 9; k++) {
File.getline(buf, 1024);
}
but i was wondering if there was a...
I'm working with Qt (version 4.6 on Windows XP 32-bit and compiling in Qt Creator 2.0.0) and trying to get a QWizard to work out.
First Problem:
I have three QWizardPages in my QWizard so far. Each page has a QVBoxLayout applied as it's layout. My first page has very small content (just a three line QLabel) but for some reason there is...
I'm trying to achieve something close to what Adobe Illustrator does with the brush tool. It correctly analyzes and simplifies the path, including its bezier handles. I implemented the Ramer–Douglas–Peucker_algorithm however, it wound up not really being what I needed. It works very well for line segments, but doesn't factor in bezier ha...
I am writing a function to rotate a NxN matrix by 90 degree.
Here is my function
// "matrix" is an n by n matrix
void rotateMatrix(int ** matrix, int n)
{
for(int layer=0; layer < n; layer++)
{
int first = layer, last = n - layer -1;
for(int i=0; i<n; i++)
{
int temp = matrix[i][last];
...
Do the methods of a member variable have access to other private member variables within the same class? I have in mind a functor member variable.
Can a pointer to a private member variable be dereferenced and assigned to, outside of the class? What about in the method of another member variable?
Maybe something like
class A
{
some...
I'm currently using boost::thread, because it very conveniently allows me to pass an arbitrary number of arguments to the thread and copies them along the way, so I don't have to worry about them being deleted before the thread launches. Is there any other library that allows this, or a way to simulate it using pthreads? I'd like to wean...
how does a call from c++ to c work internally??
...
I have a class designed to do import/export of data in one of a few different formats. Each format should have exactly the same interface, so I'm implementing it as a base class with a bunch of virtual methods and a derived class for each specific format:
#ifndef _IMPORTEXPORT_H_
#define _IMPORTEXPORT_H_
#include "stdio.h"
enum EXPORT...
PIXELFORMATDESCRIPTOR pfd = { /* otherwise fine for a window with 32-bit color */ };
HDC hDC = CreateDC(TEXT("Display"),NULL,NULL,NULL); // always OK
int ipf = ChoosePixelFormat(hDC, // always OK
SetPixelFormat(hDC,ipf, // always OK
HGLRC hRC = wglCreateContext(hDC); // always OK
wglMakeCurrent(hDC,hRC); // ! read error: 0xbaadf03...
Hello, I want to stop someone with a certain MAC address from accessing a certain port on my server, I'm using this as a sort of hardware ban for a private server a friend of mine runs.
I am looking to do this in C++, and would like to know what I would need to research in order to do it. The server runs Windows.
Also, how would I fin...
Hey all,
I have compiled succesfully the ndisprot example ndis driver that came with the Windows Driver Kit, but I don't know how to use it from C++ to send or receive packets. Could someone instruct me on how?
...
class Foo {
public:
static const int kType = 42;
};
void Func() {
Foo *bar = NULL;
int x = bar->kType;
putc(x, stderr);
}
Is this defined behavior? I read through the C++ standard but couldn't find anything about accessing a static const value like this... I've examined the assembly produced by GCC 4.2, Clang++, and Visual Studio ...
I have always heard that C++ is not Object Oriented but rather "C with Classes". So, when I mentioned to an interviewer that C++ was not really object oriented, he asked me why I didn't consider it an OO language. I haven't done any C++ since University, and I didn't have much of an answer. Is C++ Object Oriented or not? and why?
...
Error 1 error C2036: 'const void *' : unknown size file.cpp 111
I don't follow. GCC never complains about void * pointer arithmetic, even on -ansi -pedantic -Wall. What's the problem?
Here's the code-
struct MyStruct {
const void *buf; // Pointer to buffer
const void *bufpos; // Pointer to current posi...
I'm in the process of upgrading a Visual C++ 6 project to Visual Studio 2010, and I've been replacing the post-compile steps of copying files to a common location with having the output file put directly in the final location. However, for the *.tlb files that are being generated, there is an option (in project properties -> MIDL -> Outp...
Anything wrong with the following Singleton implementation?
Foo& Instance() {
if (foo) {
return *foo;
}
else {
scoped_lock lock(mutex);
if (foo) {
return *foo;
}
else {
// Don't do foo = new Foo;
// because that line *may* be a 2-step
/...
I made the following program
#include <iostream>
#include <typeinfo>
template<class T>
struct Class
{
template<class U>
void display(){
std::cout<<typeid(U).name()<<std::endl;
return ;
}
};
template<class T,class U>
void func(Class<T>k)
{
k.display<U>();
}
int main()
{
Class<int> d;
func<in...
I'm opening a database file and potentially creating it if it doesn't exist.
But for some reason, this doesn't create the table. Any ideas?
const char* sql = "CREATE TABLE IF NOT EXISTS blocks(id text primary_key,length numeric)";
sqlite3_stmt *stmt;
rc = sqlite3_prepare_v2(db_, create_table_sql, -1, &stmt, NULL);
rc = sqlite3_step(s...
In limits.h, there are #defines for INT_MAX and INT_MIN (and SHRT_* and LONG_* and so on), but only UINT_MAX.
Should I define UINT_MIN myself? Is 0 (positive zero) a portable value?
...