Hi. C++ beginner here.
If I have a class called "Animal", and a derived class "Bird : public Animal", I can create a Bird these two ways:
Animal *sparrow = new Bird;
Bird *sparrow = new Bird;
Both compile fine and work as expected. Are they equivalent? Should I prefer one over the other?
...
The little test program below prints out:
And SS Number IS =3039
I would like the number to print out with padded left zeros such that the total length is 8. So:
And SS Number IS =00003039 (notice the extra zeros left padded)
And I would like to know how to do this using manipulators and a stringstream as shown below. Thank...
I'm new to XCode. My iPhone project is dependent on FreeType. I got the source, but it needs to be statically compiled and included with my project. I tried adding a target and adding the include and src directories but this resulted in 3200 compiler errors, most of which complaining about no build rules. I'm just not sure how to do this...
Hello
I'm writing a library that has filenames as inputs. One feature that I'm trying to include is to allow the user to pass in file URLs or file paths, because sometimes the input is generated from parsing XML, other time it's not. I'm using the boost filesystem to manipulate the path, and is wondering what is the best way to conver...
Hey all -
I'm writing a multi-threaded demo program using pthreads, where one thread loads data into an STL queue, and another thread reads from it. Sounds trivial, right? Unfortunately, data pushed into the queue is vanishing. I'm not new to multithreading, nor am I unfamiliar with memory structures - however, this has me stumped.
...
Hi,
I am trying to learn the Windows API. Currently I am having a lot of trouble trying to get hooks to work. I have some sample code I have been messing around with for a few days - it has a GUI written in C# or something, and a dll in C++. The dll has this function externalized:
bool __declspec(dllexport) InstallHook(){
g_hHook ...
I'm wrapping an existing C API to make it easier to use in my VS2008 C++ program. The C API is expecting an array of "TABLE_ENTRY" structures that include a function pointer as in the code below.
But, I'm having difficulty storing a pointer to a member function in the function pointer.
Can anybody point out what I may be doing wrong?
...
Hi,
I am working on sorting several large files in C++. I have a text file containing the names of all the input files, one on each line. I would like to read the file names in one at a time, store them in an array, and then create a file with each of those names. Right now, I am using fopen and fread, which require character arrays (I ...
I'm overloading operator new, but I recently hit a problem with alignment. Basically, I have a class IBase which provides operator new and delete in all required variants. All classes derive from IBase and hence also use the custom allocators.
The problem I'm facing now is that I have a child Foo which has to be 16-byte aligned, while a...
I'm currently writing a very simple game engine for an assignment and to make the code a lot nicer I've decided to use a vector math library. One of my lecturers showed me the Sony Vector Math library which is used in the Bullet Physics engine and it's great as far as I can see. I've got it working on Linux nicely but I'm having problems...
Hello, in C++, I can easily create a function pointer by taking the address of a member function. However, is it possible to change the address of that local function?
I.e. say I have funcA() and funcB() in the same class, defined differently. I'm looking to change the address of funcA() to that of funcB(), such that at run time callin...
Possible Duplicate:
Whats your preferred pointer declaration style, and why?
I know that technically all three ways below are valid, but is there any logical reason to do it one way or the other? I mean, lots of things in c++ are "technically valid" but that doesn't make them any less foolish.
int* someFunction(int* input)
{...
I have a VS2008 C++ program where I'm wrapping a C API for use in a C++ program. The C API is expecting an array of TABLE_ENTRY values as shown below.
Other than copying the data from each of the MyClass structures in to a new TABLE_ENTRY structure in MyClassCollection::GetTable(), is there a way to get the functionality I'm looking for...
Hello, how can I divide the header and implementation of a global function?
My way is:
split.h
#pragma once
#include <string>
#include <vector>
#include <functional>
#include <iostream>
void split(const string s, const string c);
split.cpp
#include "split.h"
void split(const string& s, const string& c){
...
}
main.cpp
// mai...
I am having problems using my custom class with a std::map. The class dynamically allocates memory for members, and I do not want to use pointer in the map because I want to ensure that the class takes care of deleting all allocated memory. But the problem I am having is after I add item to map, when that block of code goes out of scop...
The return value is 4 and I'm running Visual Studio in administrative mode so permissions should be ok. I don't see anything typed out though. Any help? I'm using Windows 7 x64.
INPUT input[4];
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = 'a';
input[0].ki.dwFlags = KEYEVENTF_SCANCODE;
input[0].ki.time = 0;
i...
The main goal of the Null Object Pattern is to ensure that a usable object is provided to the client. So we want to replace the following code...
void Class::SetPrivateMemberA() {
m_A = GetObject();
}
void Class::UseA() {
if (m_A != null) {
m_A.Method();
} else {
// assert or log the error
}
}
...with...
I have a media program. i am adding CD,dvd,book info. I managed to get the book info added to the set. I am now adding the CD info. I have most of the Cd info added but i have a seperate function for adding band members. thats where i need help!
I am getting a cast error: error C2440: 'type cast' : cannot convert from 'const Item *const...
Hi to all,
i'm developing a multi-threaded application and i'm here to ask for a little help :) As i don't have much experience in multi-threading, especially in win32 API and this is my very first experience with it, i just wanted to check if I'm on the right way with my abstract model. I have read a reasonable amount of literature be...
Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc)
In Java the evaluation order is specified to be left-to-right. Is this the case for C and C++ as well, or is it implementation dependent? I do remember that the evaluation order is unspecified for function arguments, but what ab...