I am trying to pass a reference through a couple of layers of functions, and I am getting a C2664 Error. Here is my setup: I have a class [ c_ClassOne ] which contains a pointer to an object [ p_MyObject ]. I have a second class [ c_ClassTwo ] which has a function [ FunctionOne(MYOBJECTTYPE* myObject) ] I have a third class [ c_ClassThree ] which also has a function [ FunctionTwo(MYOBJECTTYPE* myObject) ] I then try to pass the reference to the pointer p_MyObject from c_ClassOne to be used within FunctionTwo. So in a function within c_ClassOne I create an instance of c_ClassTwo [ myClassTwo ] I then pass a reference to p_MyObject as follows: myClassTwo.FunctionOne(&p_MyObject); Then within FunctionOne, I create an Instance of c_ClassThree [ myClassThree ] I then attempt to once again pass the reference to p_MyObject: myClassThree.FunctionTwo(&p_MyObject); On that line I get the following error: error C2664: 'CD3DInitialize::Enumerate' : cannot convert parameter 1 from 'LPDIRECT3D9 ** ' to 'LPDIRECT3D9' Note: LPDIRECT3D9 is the Object Type of p_MyObject. Can anyone explain what I am doing wrong, and help me understand how to do it correctly? Thanks, Jody
jblau
Posts
-
Problem passing a Reference through multiple functions -
Question on HashtablesMy understanding of Hashtables is this: If I declare a Hashtable like so: Hashtable *hashMyHashtable = new Hashtable; I don't need to have a corresponding DELETE after having used the NEW for the Hashtable. The reason being that the Hashtable is a Managed object and so I don't need to Delete it in my destructor. My question is this: If I store an object that was declared with a NEW, and store it in the hashtable, do I need to go back through the hashtable and delete those objects, or does the managed code do that as well? Example: MyObject *tempObject = new MyObject; Hashtable *hashObjects = new Hashtable; hashObjects->Add(key, tempObject); So if I store several tempObjects in my hashtable, do I need to traverse through the hashtable and DELETE the tempObjects, or does the garbage collector handle this as well as the hashtable itself? If I do need to delete them, will a call to hashObjects->clear(); delete the objects? Thanks, Jody Blau
-
HashtablesThanks for all of the helpful information. As I understand it now, the way my project is setup, the hashtable is a managed object, so I can't delete it mannualy, (as I get errors when I try). So my follow up question is this: If I store an object that was declared with a NEW, and store it in the hashtable, do I need to go back through the hashtable and delete those objects, or does the managed code do that as well? Example: MyObject *tempObject = new MyObject; Hashtable *hashObjects = new Hashtable; hashObjects->Add(key, tempObject); So if I store several tempObjects in my hashtable, do I need to traverse through the hashtable and DELETE the tempObjects, or does the garbage collector handle this as well as the hashtable itself? If I do need to delete them, will a call to hashObjects->clear(); delete the objects? Thanks, Jody Blau -- modified at 15:53 Sunday 1st January, 2006
-
Hashtableswow, I am surprised at how many people responded, thanks everyone! Here is some more information which might allow you guys to set me straight. I am using Visual Studio.net 2003 The type of project that I opened is a "Windows Form Application (.Net)" (so I don't know if that means that I am using "Normal" or "Managed" C++ ?) My code is something like this: void LoadLists() { Hashtable *hashSelectedItems = new Hashtable; ......(code working with the hashtable) delete hashSelectedItems; hashSelectedItems = NULL; } When I try to build the project, I get this error message: error C3841: illegal delete expression: managed type 'System::Collections::Hashtable' does not have a destructor defined I'm thinking that perhaps it is, as one of you mentioned, being automatically managed, but I'm not certain. It was my impression that if I wanted to use a Managed object I would specifiy so in the declaration, for example, in declaring an array, if I wanted it to be a managed array I would declare it like so: int c __gc[] = new int __gc[12]; but if I didn't want it Managed, I would leave out the __gc part. ************So given all of this, what do I need to know about declaring Hashtables without leaving any memory leaks? Thanks, Jody Blau
-
HashtablesI'm a beginner programmer with a question about hashtables. when I create a hashtable like so: Hashtable *hashTable = new Hashtable; Do I need to delete the hastahble in my destructor? It was my understanding from the stuff I read that you should always have a DELETE for every NEW that you use. But when I try to delete the hashtable, I receive an error message about an illegal delete. So do I need to delete them somehow to avoid a memory leak? Thanks, Jody Blau
-
Aborting a Thread:; won't leave AbortRequested stateI am using Visual Studio.Net 2003 My mainThread creates a newThread and the newThread starts doing its thing. At some point the newThread suspends itself; at which point it enters the ThreadState of Suspended. I am trying to abort the newTread from my mainThread. When i attempt this using a newThread->abort(); It throws a ThreadStateException, i beleive because the newThread is suspended. At this point the ThreadState of newThread is (SuspendRequested, AbortRequested). So in the ThreadStateException catch, i use a newThread->Resume(); This causes the threadState of newThread to be simply (AbortRequested). The problem is that I can't figure out how to get the newThread to leave AbortRequested state and enter the Stopped state. If I call the abort from within newThread, it enters the Stopped state without problem; why can't I abort the newThread from within mainThread? any help would be appreciated, Thanks, Jody Blau
-
Listbox: How to ensure that last item added is visible?Thanks!
-
Listbox: How to ensure that last item added is visible?I am using Visual Studio.net 2003; and I don't see anything that looks like setHotItem. ???
-
ThreadingI am trying to teach myself threading from a book, but the book I have isn't helping me very much. My main thread sends off another thread. The new thread could at any given moment be either running or suspended. I want to be able to abort that thread and creat it again so that it starts at the begining of its process. The problem I am having is that depending upon whatever random moment I click the button that does this; I sometimes get either a ThreadAbortException or a ThreadStateException. For some reason my try--catch isn't catching them. I don't suppose anyone would be able to give me a little example of how to work with threads in this way????? Thanks, Jody Blau
-
Listbox: How to ensure that last item added is visible?I'm sure this is simple, i'm just not seeing it. I'm not having any luck trying to figure out how to have my listbox autoscroll to the last item in the list when a new item is added.
-
Newbie: Undeclared IdentifierI'm still a rookie, so forgive me if this is simple. I have a form and in the form's .h file i have the form's regular class stuff, but I have also added another class. For example: in my .h file i have something like this: namespace MyNamespace { public __gc class Form1 : public System::Windows::Forms::Form { //then i have all of the regular form stuff //I also have an event handler that is //like this: private: System::Void axTws1_tickPrice(System::Object * sender, AxInterop::TWSLib::_DTwsEvents_tickPriceEvent * e) { //when this event happens I want to create an //instance of another class that I have defined //within this same .h file, which you can see //below. //now when i try to do the following, i get an //error message that states that //"SymbolObject_Constructor" is an undeclared //identifier: SymbolObject_Constructor *tempObject = new SymbolObject_Constructor; }//end of event handler };//end of form class public __gc class SymbolObject_Constructor { public: String *Stock_Ticker; Decimal Bid; Decimal Ask; public: SymbolObject_Constructor() { Stock_Ticker = S""; Bid = 0.0; Ask = 0.0; } };//end of SymbolObject class }//end of namespace in my .cpp file for this form, i have a void method that creates an instance of the SymbolObject class, and I do it the same way as I attempted in the .h file; but in the .cpp file, I don't get the error message. Can anyone see what I am doing wrong? Thanks, Jody Blau
-
Newbie: Passing an object to a classThat worked great!! I had no idea I could do it like that. That opens up all sorts of possiblities for me :-D Thank you very much for taking the time to help me out! Jody Blau
-
Newbie: Passing an object to a classI am fairly new at programming; I am using Viusal Studio.net 2003. Here is the problem I am trying to solve: I have an MDI parent form which has a control. I also have a child form that needs to tell the control on the parent to do something. I seem to be able to pass the control by reference to the child form class, and if I try to manipulate the control while still in the class constructor, everything works fine. However, when I try to access it elsewhere in the child form, i get an "undeclared identifier" error. Does anyone know how to fix it? Here is some code to show what I am doing: THIS CODE IS IN THE PARENT FORM: private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { FormChild2 *formChild2 = new FormChild2(myControl); formChild2->MdiParent = this; formChild2->Show(); } THIS CODE IS IN THE FORMCHILD2 FORM: public __gc class FormChild2 : public System::Windows::Forms::Form { public: FormChild2(AxInterop::TWSLib::AxTws *myControl) { InitializeComponent(); myControl->connect("",7496,1); } }; SO while still in the class constructor I can use the "connect" property of the control, which I just passed by reference. However, I want to be able to use that control after a button_click event while in the FormChild2 form. But that is when I get the "undeclared identifier" error. Any suggestions would appreciated. Thanks, Jody Blau
-
Newbie: Create Events and EventHandlersI'm a novice programmer. I am using Visual Studio.net 2003. I am wondering if there is a way to create an event that isn't bound to a GUI control. For example: Is it possible to create an event that fires when something is added to a hashtable; OR an event that fires when a Global variable is incremented. Any info, suggestions and especically simple code examples would be greatly appreciated. thanks, Jody Blau