A scene like this:
I've different of objects do the similar operation as respective func() implements.
There're 2 kinds of solution for func_manager() to call func() according to different objects
Solution 1: Use virtual function character specified in c++. func_manager works differently accroding to different object point pass in.
...
I am writing a custom C++ exception class (so I can pass exceptions occuring in C++ to another language via a C API).
My initial plan of attack was to proceed as follows:
//C++
myClass
{
public:
myClass();
~myClass();
void foo() // throws myException
int foo(const int i, const bool b) // throws myException
} * myClassPtr;...
The definition of AudioBufferList looks weird to me… i guess my C is not so good
struct AudioBufferList
{
UInt32 mNumberBuffers;
AudioBuffer mBuffers[kVariableLengthArray];
};
typedef struct AudioBufferList AudioBufferList;
Why
AudioBuffer mBuffers[kVariableLengthArray];
and not
AudioBuffer *mBuffers;
?
kVariable...
hi, i am trying to make a linked list and create some methods. but i am getting the error
assignment makes pointer from integer without a cast.
#include <stdio.h>
#include <stdlib.h>
#include "students.h"
node_ptr create(void)
{
node_ptr students = (node_ptr) malloc(sizeof(struct node));
students->ID = 0;
students->na...
What is the simplest way to calculate the amount of even numbers in a range of unsigned integers?
An example: if range is [0...4] then the answer is 3 (0,2,4)
I'm having hard time to think of any simple way. The only solution I came up involved couple of if-statements. Is there a simple line of code that can do this without if-statemen...
Hi, I'm doing some networking programming for Windows right now envolving the HTTP protocol.
Is it possible to handle prosies at socket level? And SSL proxies? If not, does Windows provide something at a higher level to handle them? I wouldn't like to use a third party library, but if there's no other way to go I would reconsider it.
A...
I need my parent and child process to both be able to read and write the same variable (of type int) so it is "global" between the two processes.
I'm assuming this would use some sort of cross-process communication and have one variable on one process being updated.
I did a quick google and IPC and various techniques come up but I don'...
i need to send a file to a webserver using libcurl. i saw one of the examples in the curl website and am trying to implement it. it is the postit2.c example. can someone tell me how i might extend this to be able to send username and password as well
...
Hi,
I'm calling a C/C++ program from python with Popen, python code should observe behavior of child process and collect some data for his own work.
Problem is that C code already uses pipes for calling some shell commands - so after my execution from python, C program cannot execute bash shell command.
Is there any way in calling fro...
I would like to compute both the sine and co-sine of a value together (for example to create a rotation matrix). Of course I could compute them separately one after another like a = cos(x); b = sin(x);, but I wonder if there is a faster way when needing both values.
Edit:
To summarize the answers so far:
Vlad said, that there is the a...
Dear Friends,
I am trying to trace a segfault with valgrind. I get the following message from valgrind:
==3683== Conditional jump or move depends on uninitialised value(s)
==3683== at 0x4C277C5: sparse_mat_mat_kron (sparse.c:165)
==3683== by 0x4C2706E: rec_mating (rec.c:176)
==3683== by 0x401C1C: age_dep_iterate (age_dep.c:28...
I have set up the following struct:
typedef struct _thread_node_t {
pthread_t thread;
struct thread_node_t *next;
} thread_node_t;
... and then I have defined:
// create thread to for incoming connection
thread_node_t *thread_node = (thread_node_t*) malloc(sizeof(thread_node_t));
pthread_create(&(thread_node->thread), NULL, c...
It seems to be a mainstream opinion that assembly programming takes longer and is more difficult to program in than a higher level language such as C. Therefore it seems to be recommend or assumed that it is better to write in a higher level language for these reasons and for the reason of better portability.
Recently I've been writing ...
Hi,
I'm trying to extract the minimum from a binary heap but it's not working. Here's my BubbleDown code:
void heapBubbleDown(Heap * const heap, int idx) {
int min;
while(RIGHT(idx) < heap->count) {
min = LEFT(idx);
if(RIGHT(idx) < heap->count) {
if(heap->items[LEFT(idx)] > heap->items[RIGHT(idx)])...
Does the main function we define in C or C++ run in a process or thread.
If it runs in a thread, which process is responsible for spawning it
...
Suppose I have a structure in C or C++, such as:
struct ConfigurableElement {
int ID;
char* strName;
long prop1;
long prop2;
...
};
I would like to load/save it to/from the following XML element:
<ConfigurableElement ID="1" strName="namedElem" prop1="2" prop2="3" ... />
Such a mapping can be trivially done in Java/C...
typedef struct
{
uint32 item1;
uint32 item2;
uint32 item3;
uint32 item4;
<some_other_typedef struct> *table;
} Inner_t;
typedef struct
{
Inner_t tableA;
Inner_t tableB;
} Outer_t;
Outer_t outer_instance =
{
{NULL},
{
0,
1,
2,
3,
table_defined_somewhere_else,
}
};
My question i...
For example when we call say, a recursive function, the successive calls are stored in the stack. However, due to an error if it goes on infinitely the error is 'Segmentation fault' (as seen on GCC).
Shouldn't it have been 'stack-overflow'? What then is the basic difference between the two?
Btw, an explanation would be more helpful t...
Hi!
I'm working with PostgreSQL to create some data types written in C.
For example, I have:
typedef struct Point3D
{
char id[50];
double x;
double y;
double z;
} Point3D;
The input and output functions are working properly.
But the problem is the following:
Every id of Point3D must be unique (and can be NULL), so I ...
Sorry for the confusing title, but it basically says it all. Here's the structures I'm using (found in OpenCV) :
struct CV_EXPORTS CvRTParams : public CvDTreeParams
{
bool calc_var_importance;
int nactive_vars;
CvTermCriteria term_crit;
CvRTParams() : CvDTreeParams( 5, 10, 0, false, 10, 0, false, false, 0 ),
ca...