Greetings,

I have the following class

class test
{
    public:
    test():element(NULL), previous(NULL), next(NULL){};

    void *element;
    test *previous, *next;

};

this works fine: test * a_test but this crashes: test a_test does anybody know what it is that i am doing wrong? I am sure its something that has to do with the void pointer, but I dont know what i should do to fix it.

thanks in advance.

Greetings,

I have the following class

class test
{
    public:
    test():element(NULL), previous(NULL), next(NULL){};

    void *element;
    test *previous, *next;

};

this works fine: test * a_test but this crashes: test a_test does anybody know what it is that i am doing wrong? I am sure its something that has to do with the void pointer, but I dont know what i should do to fix it.

thanks in advance.

The question is a bit vague. What code didn't work for you? This compiled and ran for me.

#include <iostream>
using namespace std;


class test
{
    public:
    test():element(NULL), previous(NULL), next(NULL){};

    void *element;
    test *previous, *next;

};

int main ()
{
    test atest;
    test* atest2;
    cout << "Got this far";
    cin.get ();

    return 0;
}

The question is a bit vague. What code didn't work for you? This compiled and ran for me.

#include <iostream>
using namespace std;


class test
{
    public:
    test():element(NULL), previous(NULL), next(NULL){};

    void *element;
    test *previous, *next;

};

int main ()
{
    test atest;
    test* atest2;
    cout << "Got this far";
    cin.get ();

    return 0;
}

thanks for answering VernonDozier

when i instantiate a test object (not as pointer)
eg. test o;
it compiles but when i try to run, i get an unhandled win32 exception.
there is nothing else in my main except for the instantiation.
I am using codeblocks ide and gcc compiler.

thanks for answering VernonDozier

when i instantiate a test object (not as pointer)
eg. test o;
it compiles but when i try to run, i get an unhandled win32 exception.
there is nothing else in my main except for the instantiation.
I am using codeblocks ide and gcc compiler.

Please post the code that gave you the run-time error.

Please post the code that gave you the run-time error.

:$ never mind, I just found the mistake.
Thanks for your help mate. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.