473,385 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Funktion calls in different classes

I have a coding problem. I hope I can explain it well enough.

I’m using VC++.NET, managed window forms

I want a dialog window change some process going on controlled by a class
defined in my main window form class.

Let my give you some code snippets to make it clearer (hopefully):

public class someclass
{
//code goes here
};

public: __gc class fclDialog
{
public:
void DoSomethingToo(void)
{
fclMainWindow->DoSomethig();
}
};

public __gc class fclMainWindow
{
public:
someclass A = new someclass;
void DoSomething(void)
{
//Code that effects “someclass”
A->…
};

void OpenDialog(void)
{
fclDialog *DlgForm = new fclDialog();
DlgForm->Show();
};
};

I hope you can see what I’m trying to do. A function in the Dialog class has
to call a function in the MainWindow class from which it has been created and
called. When I try to compile my code I get an error saying that I can’t call
a non static function like this, and if I use the keyword static (static void
DoSomething(void)) I get an error saying it can not be used on functions with
file scope. What do I have to change?

Chris
Nov 17 '05 #1
1 829

"cnickl" <cn****@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
I have a coding problem. I hope I can explain it well enough.

I'm using VC++.NET, managed window forms

I want a dialog window change some process going on controlled by a class
defined in my main window form class.

Let my give you some code snippets to make it clearer (hopefully):

public class someclass
{
//code goes here
};

public: __gc class fclDialog
{
public:
void DoSomethingToo(void)
{
fclMainWindow->DoSomethig();
}
};

public __gc class fclMainWindow
{
public:
someclass A = new someclass;
void DoSomething(void)
{
//Code that effects "someclass"
A->.
};

void OpenDialog(void)
{
fclDialog *DlgForm = new fclDialog();
DlgForm->Show();
};
};

I hope you can see what I'm trying to do. A function in the Dialog class has to call a function in the MainWindow class from which it has been created and called. When I try to compile my code I get an error saying that I can't call a non static function like this, and if I use the keyword static (static void DoSomething(void)) I get an error saying it can not be used on functions with file scope. What do I have to change?

Chris


Chris,

I'm not sure what you are trying to achieve, but
you might consider passing a pointer to the main window
in the constructor of the dialog so that you can
call the DoSomething method of the instance of
the main window that created the dialog. Something
like

public: __gc class fclDialog
{
private:
fclWindow* m_fcw;
public:
fclDialog(fclWindow* fcw) : m_fcw(fcw) {}
void DoSomethingToo(void)
{
m_fcw->DoSomething();
}
};
public __gc class fclMainWindow
{
public:
...

void OpenDialog(void)
{
fclDialog *DlgForm = new fclDialog(this);
DlgForm->Show();
};
};

HTH,

--
Akin

aknak at aksoto dot idps dot co dot uk
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Carramba | last post by:
hi! I don't have eny code to chare, this is just teoretical question. usualy you have for looks like <form method="POST" action="some_php_script.php"> namn: <input type="text" name="name"...
1
by: Robert Dick | last post by:
Derived classes sometimes need to delegate portions of the work in overridden methods to methods in their base classes. This was traditionally done with explicit calls in python, e.g., class...
1
by: Torsten Mohr | last post by:
Hallo, ich möchte eine Funktion schreiben, der ich eine Referenz auf einen String übergeben kann und die dann einige Änderungen am String vornimmt. In Perl würde ich also ein \$string...
0
by: Lefevre | last post by:
Hello I recently had troubles with a class inheritance hierarchy. I solved it, but it didn't satisfied me. I found the solution using this forum :) Actualy i found the following message...
6
by: Richard Berg | last post by:
Hello, I need implementation advice: I am writing a program that should call some API functions in a specific order. The APIs are for another application, not Windows APIs. The order and type...
1
by: Peter Br | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived...
2
by: Peter Br | last post by:
A Question to the C#/.Net Gods of this forum: are there performance penalties when i compile (C#, FW1.1, ASP.NET, Studio2003) a central baseclass in a different assembly than all the derived...
4
by: ulikoehler | last post by:
Hallo! Ich suche fr mein Programm eine Zufalsszahl-Funktion, die eine groe Anzahl von 'Zufalls'-Zahlen in einer kleinen Zeit generiert (~50000/s). Muss ich mir diese selbst programmieren oder ist...
12
by: Peter Cranz | last post by:
hello, I've got the following problem: I have a construct similar like this: namespace A { class X {
6
by: Dasn | last post by:
Hi, there. 'lines' is a large list of strings each of which is seperated by '\t' I wanna split each string into a list. For speed, using map() instead of 'for' loop. 'map(str.split, lines)'...
1
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.