c++

Dynamically Growing an Array in C++

I have an array of pointers of CName objects. I have the following constructor which initializes my array to size one. Then when I add an object I grow the array by 1 and add the new object. It compiles fine, however when I try to print them I just get segmentation fault error. Can you look and see if I'm doing anything wrong? //cons...

Make a friend class have only special access to 1 function of another class?

Possible Duplicate: Is this key-oriented access-protection pattern a known idiom? I have class A and class B. I want class A to access one of class B's private functions, but only that, not everything else. Is that possible? Thanks Some kind of example: class A { //stuff }; class B { int r; //A cant use this MagicFriendKe...

C++: Trouble with Parsing XML using Libxml

I am having a lot of trouble working with the libxml2 library to parse an xml file. I have weeded out a previous, similar problem, but have run into another. Here is the problem code: class SSystem{ public: //Constructors SSystem(){}; //Make SSystem from XML Definition. Pass ptr to node SSystem(xmlNodePtr Nptr, xmlDocP...

Is there any way to make a variable length array global in c++?

I've created a variable length array in one function, however I need to refer to this array in a second function. The problem occurs when I put the declaration above main() seeing as its length hasn't been defined yet, my compiler gets angry. How does one typically go about this? EDIT: Here is my code so far. I need to make the ar...

Scope resolution operator and dependent name

I have the following test code #include <iostream> template <typename T> struct PS { template <typename U> static void foo() { std::cout<<"Some test code"; } }; template <typename T> void bar() { PS<T>::template foo<T>(); //won't compile without `::template` } int main() { bar<int>(); } ISO C++03 14.2/4: sa...

Shuffle array variables in a pre-specified order, without using extra memory of "size of input array"

Input : A[4] = {0,4,-1,1000} - Actual Array P[4] = {1,0,3,2} - Order to be reshuffled Output: A[4] = {4,0,1000,-1} Condition : Don't use an additional array as memory. Can use an extra variable or two. Problem : I have the below program in C++, but this fails for certain inputs of array P. #include<iostream> using nam...

WMI Win32_PhysicalMedia SerialNumber

I am using WMI with C++ to get the physical disk serial number. On Windows 7 64bit, I get a string with the serial number. While when running the same application on a Windows XP 64bit machine I get a hexadecimal string with each char's values reversed. I have noticed 3 different behaviours so far: Windows 7 64bit String in correct ...

How to check if a std::string is set or not?

Hi, If using a char*, I can initialize it to NULL and later check if it is set by doing a comparison. How to do the same thing for a std::string? How to check if the string is set or not? EDIT: What if the string I set to is also empty? Do I have to use an additional flag to check if the std::string is set or not? ...

Data structure for string indices?

I'm looking for a data structure for string(UTF-8) indices that is highly optimized for range queries and space usage. Thanks! Elaboration: I have list of arbitrary length utf-8 strings that i need to index. I will be use only range queries. Example: I have strings - apple, ape, black, cool, dark. Query will be something like this -...

C++ floats being converted to ints

I have the following function that should return an average of l1- l7. However, it seems to only return an integer. Why is it doing this, and how do I make it return a float rounded to 2 decimal places? Snippet: int lab_avg(int l1,int l2,int l3,int l4,int l5,int l6,int l7) { float ttl; ttl = l1 + l2 +l3 +l4 +l5 +l6 +l7; re...

How should I pass a std::string to a function?

Hi, Should I always pass a std::string by const reference to a function if all that is done inside that function is to copy that string? Additionally, what is the difference (perf or otherwise) between passing by value and passing by reference? As I understand, one uses operator= and the other copy constructor. Is that the case? ...

How to work with files in XPCOM

Hi all, I'm writing a Mozilla component to get all the links from a page an write them into a file using XPCOM and C++. I get all the links into an array like this: //doc is a pointer to nsIDOMDocument doc->GetElementsByTagName(NS_LITERAL_STRING("A"), getter_AddRefs(nodeList)); nodeList->GetLength(&nodeNumb); href = new nsEmbedString[...

Anyone know how malloc_info() works?

Hi, I've been trying to figure out how the malloc_info() function located in malloc.h works. I know you have to pass it a FILE* and that no options are implemented yet, but I am at a loss as to what it is actually reporting!? Furthermore i've written a test app that allocates a whole bunch of memory and the values reported from malloc_i...

Dynamically create thread in c++

hello, i have an queue of urls and i an processing it with some function i need to run some 10 thread to read 10 website at same time ,,, boost::thread tl(boost::bind(&thread::start, crawl, url)); we can use for loop but is that is the only way to use to create dynamic thread.... Edited while(!q.empty()) { ...

Help me convert this Java function to C++

Hi everyone. I've been following this forum for sometime now but officially registered today. I'm a Java guy learning C++ now. As an exercise I'm started to rewrite some of the Java code I had written (while I was learning it ) now in C++. There are several questions here that helped me a lot. But I'm stuck now and need some help. Th...

How to get into "The zone"

Hi, As I see there are lots of bright people here, I'll ask away. I don't know if this question has been asked before - most probably it has been. Duplicate this if so. For anyone who does not know what "the zone" for programmers is, it is when you are at your most productive and it feels like you are not coding but the code is writin...

Access variable through memory location

I get wrong value when accessing variabel v2 using their memory location when HWND is before bool variable. If Ii use HWND after bool then I get correct result. Using instance variable (t) I get correct value for v1 and v2 such as t->v1 and t->v2. I am using Windows Server 2003. I have the following Test class. this is only reproducible...

Detecting bits per pixel in a TIFF image

Handling monochrome tiff image using LibTiff, I can read "Bits per sample" parameter: TIFFTAG_BITSPERSAMPLE. When it returns 16, actual "Bits per pixel" value for such image may be any value from 9 to 16, in most cases this is 10, 12, 14 or 16. Is there any tiff image tag that keeps this value? ...

SQL engine for only SELECT statment - hand written parser in c++

Hi, I am a newbie of compilers, but i got a project SQL engine - for only select statement. For this i have to use only hand written parser and engine. I studied the samples of LL(k) grammar and recursive descent techniques(suggested by stackoverflow for writing parser by hand). But in any of the samples, didn't find the way to construc...

Double buffering winAPI

Okay, so in my application, there are a bunch of winAPI and a few custom controls. Yay... Now, normally, they will just quietly redraw themselves for animations, state changing, ect.... and it all works fine. But I have a method of class Window called fix(). This is called whenever the whole window needs to be updated. It resizes the c...