Hello all,
I've them following C-code wich I need to compile with a c++ compiler. This
is only one error, but I'm trying to fix it for days now, without any
result. It's about the following line:
node *n = malloc(sizeof(node));
This is the complete code of the method
node *list_add(node **p, int i) {
node *n = malloc(sizeof(node));
n->next = *p;
*p = n;
n->data = i;
return n;
}
Anyone has a solution for this problem?
Thanks! 3 9431
On Thu, 14 Sep 2006 13:39:27 +0200 in comp.lang.c++, "Joah Senegal"
<bl****@hva.nlwrote,
>Hello all,
I've them following C-code wich I need to compile with a c++ compiler. This is only one error, but I'm trying to fix it for days now, without any result. It's about the following line:
node *n = malloc(sizeof(node));
void* conversion is automatic in C; in C++ you have to ask for it.
node *n = (node *) malloc(sizeof(node));
Joah Senegal wrote:
Hello all,
I've them following C-code wich I need to compile with a c++
compiler. This is only one error, but I'm trying to fix it for days
now, without any result. It's about the following line:
node *n = malloc(sizeof(node));
This is the complete code of the method
node *list_add(node **p, int i) {
node *n = malloc(sizeof(node));
n->next = *p;
*p = n;
n->data = i;
return n;
}
Anyone has a solution for this problem?
In C++, you should replace malloc() calls with new.
node *n = new node;
Usually better yet is to get rid of hand-rolled linked-lists, and use
the standard list container.
Brian
Default User wrote:
Joah Senegal wrote:
Hello all,
I've them following C-code wich I need to compile with a c++
compiler. This is only one error, but I'm trying to fix it for days
now, without any result. It's about the following line:
node *n = malloc(sizeof(node));
This is the complete code of the method
node *list_add(node **p, int i) {
node *n = malloc(sizeof(node));
n->next = *p;
*p = n;
n->data = i;
return n;
}
Anyone has a solution for this problem?
In C++, you should replace malloc() calls with new.
node *n = new node;
Usually better yet is to get rid of hand-rolled linked-lists, and use
the standard list container.
but given the whole code is written in C and he may want to compile it
in C, the C-style cast is probably the best option, as it works in C as
well.
When he wants to write a C++ version, a whole rewrite (using std::list
or some other container) would be suggested. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thomas Barth |
last post by:
Hi,
I'm new to windows programming and still reading a book about
windows-programming with C++. I copied the following code from
the book into my ide (Eclipse/CDT) to comprehend the code, but
two...
|
by: Richard G. Riley |
last post by:
Would it be wrong to use "implicit casting" instead of the standards
"implicit conversion" when talking about implicit conversions between
certain data types. The standard mentions "explicit...
|
by: philwozza |
last post by:
Im trying to implement a THREAD class that encapsulates a posix thread.
Here is an outline of my THREAD class.
class THREAD {
public:
// returns 1 if thread sucessfully started
int...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm using this alloc_mem-function:
- - - - - - - - - - - - - - - - - - - - - - - -
void *alloc_mem (size_t num_elems, size_t elem_size,
char *filename, int line,
size_t *total_mem)
{
|
by: tkirankumar |
last post by:
Hi all,
uname -a
SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M
g++ -v
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs
Configured with:...
|
by: haomiao |
last post by:
I want to implement a common list that can cantain any type of data,
so I declare the list as (briefly)
---------------------------------------
struct list
{
int data_size;
int node_num;...
|
by: fazulu deen |
last post by:
Hi all,
For the following code :
file_ptr = fopen("pass_fail.txt", "a"); // error line 393
fdisplay(file_ptr, "Test Passed");
fclose(file_ptr);
|
by: Nozdormu |
last post by:
Hi guys, I have a quick question. The language I'm using is C.
The question I'm tackling:
Write a program that
(1) defines a 1D array with ten int elements, and
(2) sets the values of the...
|
by: Tex08 |
last post by:
I have hit a roadblock on a class project. Trying to implement the composite pattern with separate classes to represent a boolean expression. My literal class will not compile (g++, required...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |