|
See here.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
How do I set up a two way communication between two classes?
Lets say I have Class A and Class B . Now, Class A must be able to call functions of Class B and Class B must be able to call functions of Class A .
Is it possible?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
Hakuna-Matada wrote: ets say I have Class A and Class B. Now, Class A must be able to call functions of Class B and Class B must be able to call functions of Class A.
FORWARD Decalartion is the key to your Question!
eg
class a;
class b{
public:
a aObj;
};
class a
{
public:
b bObj;
};
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Yes it's possible, but you'll have to seperate declaration from implementation:
In .h:
<br />
class A;<br />
class B;<br />
<br />
class A<br />
{<br />
public:<br />
B* m_pB;<br />
<br />
void callB();<br />
void doSomething();<br />
};<br />
<br />
class B<br />
{<br />
public:<br />
A* m_pA;<br />
<br />
void callA();<br />
void doSomething();<br />
};<br />
In .cpp:
void A::callB()<br />
{<br />
m_pB->doSomthing();<br />
}<br />
<br />
void A::doSomething()<br />
{<br />
}<br />
<br />
void B::callA()<br />
{<br />
m_pA->doSomthing();<br />
}<br />
<br />
void B::doSomething()<br />
{<br />
}<br />
Usage:
A a;<br />
B b;<br />
<br />
a.m_pB = &b;<br />
b.m_pA = &a;<br />
<br />
a.callB();<br />
b.callA();<br />
Pretty generic, hope that helps.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Hakuna-Matada wrote: Is it possible?
In addition to Steve's suggestion, the methods that you wish to invoke could be made static . That way, a class does not have to contain an instance of the other.
class A
{
public:
static fooA();
};
class B
{
public:
static fooB();
}; Now in class A 's methods, you can call B::fooB() , and in class B 's methods, you can call A::fooA() .
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hey guys.
What do you recommend as the quickest method of finding duplicate values in a list of items or array.
These item type could be numeric or (in this case) a string.
In the past I've used the technique of inserting the items in an stl set. This would immediately flag if you are trying to insert the same item again. But this can get slow if I have a large list of items to wade through.
Are there any other techniques that you guys are using?
I Dream of Absolute Zero
|
|
|
|
|
If your list is sorted, you could use a binary search http://en.wikipedia.org/wiki/Binary_search[^].
If not sorted, you'll have to scan the entire list/array for duplicates. Re-creating your list, just to determine if there are duplicates, would not be the most efficient way to do it - just run a loop over the original list/array.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Thanks. I'll do a quick sample test project to check the speed between the two methods.
The std::set insertion technique works fine (just finished the coding), but I suspect that it is not the fastest way of doing this.
I Dream of Absolute Zero
|
|
|
|
|
Hi all,
I crated a new dialog called IDD_RIPORTO.
I also added a class called riporto.
If i do:
riporto temp;
temp.DoModal();
everything is ok, but if i do:
riporto* temp = new riporto();
temp->Create(IDD_RIPORTO,this);
the application runs but crashes at runtime
when the above code is executed.
If i do:
CDialog *temp = new CDialog();
temp->Create(IDD_RIPORTO,this);
everything goes well but of course
i have no access to riporto data members,
so i think this isn't the correct way.
Where i go wrong ?
Thank you so much,
Deamo16.
|
|
|
|
|
Desmo16 wrote: riporto* temp = new riporto();
temp->Create(IDD_RIPORTO,this);
Read the article in MSDN regarding modeless dialog.
It clearly say that, you need customized contructor to create that dialog.
the default constructor of you dialog class calls CDialog(IDD); to initialize the dialog with template.
Desmo16 wrote: temp->Create(IDD_RIPORTO,this);
you are trying to create on already created object. So it wont work.
define you own contructor to create modeless dialog. never allow contructor to create dialog with template if you are looking for a modeless dialog.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
<blink>My Blog | Understanding State Patte
|
|
|
|
|
when you run Domodal() is ok but when you use create you get error or no?
whitesky
|
|
|
|
|
when i use create i get error at runtime.
I'd like to understand how to write my own
constructor as i was told to do in the previous post
or if there's a sample coda somewhere.
|
|
|
|
|
You using
riporto* temp = new riporto();<br />
temp->Create(IDD_RIPORTO,this); and you get error
and if you use this way you get error or no and answer to me,please
<br />
riporto* temp = new riporto(this);<br />
riporto::riporto(CWnd* pParent )<br />
: CDialog(CTest2::IDD, pParent)<br />
{<br />
BOOL o=Create(IDD,Parent);
}<br />
whitesky
|
|
|
|
|
riporto * dlg;
dlg = new riporto(this);
dlg.create(IDD_RIPORTO);
dlg->ShowWindow(1);
tell me wheather it works or not
Ashish Dogra
MCA
Noida
|
|
|
|
|
i tried both methods but with no success.
|
|
|
|
|
is there somwthing wrong in the fact that i don't create the class "by hand"
but use the wizard ?
|
|
|
|
|
when you used from this code do you use breakpoint and yes whats error?
whitesky
|
|
|
|
|
CMyDialog* pDialog;
void CMyWnd::OnSomeAction()
{
//pDialog initialized to NULL in the constructor of CMyWnd class
pDialog = new CMyDialog();
//Check if new succeeded and we got a valid pointer to a dialog object
if(pDialog != NULL)
{
BOOL ret = pDialog->Create(IDD_MYDIALOG,this);
if(!ret) //Create failed.
AfxMessageBox("Error creating Dialog");
pDialog->ShowWindow(SW_SHOW);
}
else
AfxMessageBox("Error Creating Dialog Object");
}
//copy from MSDN
Use the WS_VISIBLE style in the dialog-box template if the dialog box should appear when the parent window is created. Otherwise, you must call ShowWindow. For further dialog-box styles and their application, see the DLGTEMPLATE structure in the Platform SDK and Window Styles in the MFC Reference.
Huynhnb
.: Your success is also me :.
|
|
|
|
|
if you have a class Dialog you can use
<br />
riporto * dlg;<br />
dlg = new riporto();<br />
dlg->create(IDD_RIPORTO);<br />
dlg->ShowWindow(1); <br />
whitesky
|
|
|
|
|
Desmo16 wrote: temp->Create(IDD_RIPORTO,this);
Move the call to Create() to the constructor:
riporto::riporto( CWnd* pParent ) : CDialog(riporto::IDD, pParent)
{
Create(IDD);
} Now you can create and display the dialog via:
riporto *pDlg = new riporto;
pDlg->ShowWindow(SW_SHOW);
...
pDlg->DestroyWindow(); Desmo16 wrote: the application runs but crashes at runtime
Have you narrowed the "crash" down to a single statement?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
i've got a trouble calling Create()
the error is:
"riporto::Create": impossible converting parameter 1 from "int" to "LPCTSTR"
|
|
|
|
|
I have a function in cpp file returning int * array and taking int * array as a parameter. It is as:
int * funcArg(int *a ) {
int DLLArg [] = {100,200,300};
a=DLLArg;
return a;
};
I have exported this function in the dll (i have checked it with dumpbin.exe)
But I can not handle this function in c# client. My code in c# is as: ( ıt gives this error. "An unhandled exception of type 'System.Runtime.InteropServices.SafeArrayRankMismatchException' occurred in CSharpClient.exe
Additional information: Safe array of rank 51241 has been passed to a method expecting an array of rank 1."
What should I do? URGENT help!!!
namespace CSharpClient
{
class Class1
{
[DllImport("DenemeNonMfcDll.dll",EntryPoint="?Sub@DLLclass@@QAEHHH@Z")]
public extern static int Sub(int a, int b);
[DllImport("DenemeNonMfcDll.dll")]
[return: MarshalAs(UnmanagedType.SafeArray)]
public extern static int [] funcArg(int [] a);
public static int [] intArray = new int [3] {0,1,2} ;
static void Main(string[] args)
{
foreach (int num in funcArg(intArray) )
{
System.Console.WriteLine(num.ToString());
}
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
|
|
|
|
|
You are trying to return a pointer to an array on the stack. There is no guarantee that your array will still be there when your function returns. You are passing in a parameter "int *a" which you never use.
Was this your intention?
int * funcArg(int *a)
{
a[0] = 100;
a[1] = 200;
a[2] = 300;
return a;
};
Most people usually have another parameter for the calling function to tell the callee the size of the array being passed so the callee won't exceed the buffer.
|
|
|
|
|
My aim is to write a function returning int array and taking an int array as a parameter such as
int * funcArg(int *a){
return a;
};
I will export it from c++ dll and I will use this function in c#. I will call it like
[DllImport("DenemeNonMfcDll.dll")]
[return: MarshalAs(UnmanagedType.SafeArray)]
public extern static int [] funcArg(int [] a);
But C# can not handle it this way. And I coul not find a way doing this. Either I can change c++ code or c# code. But I could not find a solution to make an interoperation between c++ and c#
|
|
|
|
|