The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

C++ help

curbycurby Registered User regular
edited December 2006 in Help / Advice Forum
I'm trying to make a global pointer variable of type node in C++ in managed mode. I get this error:
Error 1 error C3145: 'start' : global or static variable may not have managed type 'node ^'
ref struct node{
	int data;
	node ^ prev;
	node ^ next;
	};

node ^ start;

int main(...

So how can I make a global variable node?

linktous.gif
curby on

Posts

  • SevorakSevorak Registered User regular
    edited December 2006
    I don't think you can have a managed handle in global space, at least not without some effort and utility classes. Why do you need it to be global?

    Sevorak on
    steam_sig.png 3DS: 0748-2282-4229
  • curbycurby Registered User regular
    edited December 2006
    I'm making a linked list in managed mode, and I'm trying to use functions. I'm not sure how to pass "node ^ start" to "void addFront()"...

    That would be good advice as well.

    curby on
    linktous.gif
  • curbycurby Registered User regular
    edited December 2006
    node addFront(node);
    
    main(...){
    if (choice == 1){addFront(start);}
    }
    
    node addFront(node^start){}
    
    Error 1 error C2664: 'addFront' : cannot convert parameter 1 from 'node ^' to 'node'

    Variations of start in main yield similar results.

    curby on
    linktous.gif
  • SevorakSevorak Registered User regular
    edited December 2006
    Well, first of all I would recommend making a full blown LinkedList class instead of doing it c style with pointers, because managed c++ was made to be more object oriented than c++.

    That said, your addFront function's signature should look something like
    node ^addFront(node ^list, int data)
    

    Sevorak on
    steam_sig.png 3DS: 0748-2282-4229
  • SevorakSevorak Registered User regular
    edited December 2006
    curby wrote:
    node addFront(node);
    
    main(...){
    if (choice == 1){addFront(start);}
    }
    
    node addFront(node^start){}
    
    Error 1 error C2664: 'addFront' : cannot convert parameter 1 from 'node ^' to 'node'

    Variations of start in main yield similar results.

    You're getting that error because you're declaring that addFront takes a 'node' not a 'node ^'. A 'node' and 'node ^' are different types, just like 'int' and 'int *' are different types.

    Edit: So you're second definition of addFront is an overload, not the definition of the one you declared above main, because the parameter types differ.

    Sevorak on
    steam_sig.png 3DS: 0748-2282-4229
Sign In or Register to comment.