Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Problem using more classes...
Problem using more classes... [message #35645] Fri, 09 March 2012 17:18 Go to next message
idkfa46 is currently offline  idkfa46
Messages: 139
Registered: December 2011
Experienced Member
Hello guys,
I am back looking for your help again...

I have some troubles calling back functions from different classes... here an example for an easier explanation:

main.cpp
#include "prova3.h"

prova3::prova3()
{
	CtrlLayout(*this, "Window title");
	x <<= THISBACK(a);
	y <<= THISBACK(a);
	x2 <<= THISBACK(b);
	y2 <<= THISBACK(b);
}
void prova3::a()
{
	if ( !x.IsNullInstance() && !y.IsNullInstance())
	{
		tot = prod(x,y);
	}
	else
	{
		tot = Null;
	}
}
void prova3::b()
{
	if ( !x2.IsNullInstance() && !y2.IsNullInstance())
	{
		tot2 = prova4::sum(x,y);
	}
	else
	{
		tot = Null;
	}
}
int prova3::prod (int x, int y)
{
	return x*y;
}
int prova4::sum (int x, int y)
{
	return x+y;
}
GUI_APP_MAIN
{
	prova3().Run();
}


prova3.h
#ifndef _prova3_prova3_h
#define _prova3_prova3_h
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#define LAYOUTFILE <prova3/prova3.lay>
#include <CtrlCore/lay.h>

class prova3 : public Withprova3Layout<TopWindow> {

public:
	void a();
	void b();
	
	int prod (int x, int y);

	typedef prova3 CLASSNAME;
	prova3();
};

class prova4 {
public:
	int sum (int x, int y);
};
#endif


prova3.lay
LAYOUT(prova3Layout, 403, 257)
	ITEM(EditInt, y, LeftPosZ(45, 64).TopPosZ(92, 19))
	ITEM(EditInt, y2, LeftPosZ(161, 64).TopPosZ(92, 19))
	ITEM(EditInt, x, LeftPosZ(47, 64).TopPosZ(57, 19))
	ITEM(EditInt, x2, LeftPosZ(161, 64).TopPosZ(57, 19))
	ITEM(Label, dv___4, SetLabel(t_("x")).LeftPosZ(10, 33).TopPosZ(57, 21))
	ITEM(Label, dv___5, SetLabel(t_("y")).LeftPosZ(10, 33).TopPosZ(92, 21))
	ITEM(EditInt, tot, LeftPosZ(47, 64).TopPosZ(130, 19))
	ITEM(EditInt, tot2, LeftPosZ(160, 64).TopPosZ(130, 19))
END_LAYOUT


calling function prod() from the same class (prova3) there are no problems but if i try to call back sum(x,y) from a different class (prova4) i receive the following error:

'prova4::sum' : illegal call of non-static member function
c:\myapps\prova3\prova3.h(28) : see declaration of 'prova4::sum'

Where I'm wrong today ?!

Regards,
Matteo
Re: Problem using more classes... [message #35654 is a reply to message #35645] Sat, 10 March 2012 13:49 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 299
Registered: November 2008
Experienced Member
Hello, Matteo.
idkfa46 wrote on Fri, 09 March 2012 17:18

calling function prod() from the same class (prova3) there are no problems but if I try to call back sum(x, y) from a different class (prova4) I receive the following error:

'prova4::sum' : illegal call of non-static member function
c:\myapps\prova3\prova3.h(28) : see declaration of 'prova4::sum'

Where I'm wrong today ?!


As compiler message said, you need static prova4::sum function to use it this way:
class prova4 {
public:
	static int sum (int x, int y) { return x + y; }
};

Else you need to create object instance of prova4 class for using it:
prova4 p;
int result = p.sum(1, 2);
Re: Problem using more classes... [message #35692 is a reply to message #35654] Tue, 13 March 2012 17:26 Go to previous message
idkfa46 is currently offline  idkfa46
Messages: 139
Registered: December 2011
Experienced Member
Thanks... Working now Very Happy
Previous Topic: array : minimum value
Next Topic: Sizeable().Zoomable()
Goto Forum:
  


Current Time: Thu May 28 00:20:27 CEST 2020

Total time taken to generate the page: 0.01964 seconds