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 » U++ Library support » U++ Core » Function.h: "expression cannot be used as a function"
Function.h: "expression cannot be used as a function" [message #49358] Wed, 31 January 2018 12:44 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi folks,
I have an application developed on Windows platform, that compiles and works fine. Now I am in the process to port it on a linux platform. When I try to compile it with gcc, I get the following error: "expression cannot be used as a function" on line 17 of Function.h. I am using Ultimate++ 2017.2. It is unclear if the error is triggered by some code I wrote even if it shows up in that file. In the past I compiled the same program on linux using an older version of Ultimate++ and it compiled without problems.
Regards,
Gio
Re: Function.h: "expression cannot be used as a function" [message #49359 is a reply to message #49358] Wed, 31 January 2018 13:11 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

Please post full compilation error - it will save our time on investigation the problem.

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: Function.h: "expression cannot be used as a function" [message #49360 is a reply to message #49359] Wed, 31 January 2018 14:26 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
This is the complete output.

Note that /home/pi/MyApps/StatusDetector/AggiungiComm.cpp:149 is the last line of the file (and is blank).

----- CtrlLib ( GUI SSE2 GCC SHARED POSIX LINUX ) (1 / 19)
----- MySql ( GUI SSE2 NOMYSQL GCC SHARED POSIX LINUX ) (2 / 19)
----- SqlCtrl ( GUI SSE2 GCC SHARED POSIX LINUX ) (3 / 19)
----- Barcode ( GUI SSE2 GCC SHARED POSIX LINUX ) (4 / 19)
----- MyINI ( GUI SSE2 GCC SHARED POSIX LINUX ) (5 / 19)
----- PostgreSQL ( GUI SSE2 GCC SHARED POSIX LINUX ) (6 / 19)
----- CtrlCore ( GUI SSE2 GCC SHARED POSIX LINUX ) (7 / 19)
----- PdfDraw ( GUI SSE2 GCC SHARED POSIX LINUX ) (8 / 19)
----- Draw ( GUI SSE2 GCC SHARED POSIX LINUX ) (9 / 19)
----- plugin/bmp ( GUI SSE2 GCC SHARED POSIX LINUX ) (10 / 19)
----- RichText ( GUI SSE2 GCC SHARED POSIX LINUX ) (11 / 19)
----- Core ( GUI SSE2 GCC SHARED POSIX LINUX ) (12 / 19)
----- plugin/png ( GUI SSE2 GCC SHARED POSIX LINUX ) (13 / 19)
----- Sql ( GUI SSE2 GCC SHARED POSIX LINUX ) (14 / 19)
----- plugin/z ( GUI SSE2 GCC SHARED POSIX LINUX ) (15 / 19)
----- Report ( GUI SSE2 GCC SHARED POSIX LINUX ) (16 / 19)
----- CodeEditor ( GUI SSE2 GCC SHARED POSIX LINUX ) (17 / 19)
----- plugin/pcre ( GUI SSE2 GCC SHARED POSIX LINUX ) (18 / 19)
----- StatusDetector ( GUI SSE2 NOMYSQL MAIN GCC SHARED POSIX LINUX ) (19 / 19)
AggiungiComm.cpp
In file included from /home/pi/upp/uppsrc/Core/Core.h:304:0,
                 from /home/pi/MyApps/StatusDetector/StatusDetector.h:23,
                 from /home/pi/MyApps/StatusDetector/AggiungiComm.h:5,
                 from /home/pi/MyApps/StatusDetector/AggiungiComm.cpp:1:
/home/pi/upp/uppsrc/Core/Function.h: In instantiation of 'Res Upp::Function<Res(ArgTypes ...)>::Wr
    apper<F>::Execute(ArgTypes ...) [with F = const char*; Res = void; ArgTypes = {}]':
/home/pi/MyApps/StatusDetector/AggiungiComm.cpp:149:1:   required from here
/home/pi/upp/uppsrc/Core/Function.h:17:60: error: expression cannot be used as a function
   virtual Res Execute(ArgTypes... args) { return fn(args...); }
                                                            ^
/home/pi/upp/uppsrc/Core/Function.h:17:60: warning: return-statement with a value, in function ret
    urning 'void' [-fpermissive]
/home/pi/upp/uppsrc/Core/Function.h: In instantiation of 'Res Upp::Function<Res(ArgTypes ...)>::Wr
    apper<F>::Execute(ArgTypes ...) [with F = int; Res = void; ArgTypes = {}]':
/home/pi/MyApps/StatusDetector/AggiungiComm.cpp:149:1:   required from here
/home/pi/upp/uppsrc/Core/Function.h:17:60: error: expression cannot be used as a function
/home/pi/upp/uppsrc/Core/Function.h:17:60: warning: return-statement with a value, in function ret
    urning 'void' [-fpermissive]
/home/pi/upp/uppsrc/Core/Function.h: In instantiation of 'Res Upp::Function<Res(ArgTypes ...)>::Wr
    apper<F>::Execute(ArgTypes ...) [with F = Upp::GateN<>; Res = void; ArgTypes = {}]':
/home/pi/MyApps/StatusDetector/AggiungiComm.cpp:149:1:   required from here
/home/pi/upp/uppsrc/Core/Function.h:17:60: warning: return-statement with a value, in function ret
    urning 'void' [-fpermissive]
StatusDetector: 1 file(s) built in (0:14.29), 14291 msecs / file, duration = 14305 msecs, parallel
    ization 0%

There were errors. (0:14.48)

[Updated on: Wed, 31 January 2018 14:39]

Report message to a moderator

Re: Function.h: "expression cannot be used as a function" [message #49362 is a reply to message #49358] Wed, 31 January 2018 18:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Giorgio wrote on Wed, 31 January 2018 12:44
Hi folks,
I have an application developed on Windows platform, that compiles and works fine. Now I am in the process to port it on a linux platform. When I try to compile it with gcc, I get the following error: "expression cannot be used as a function" on line 17 of Function.h. I am using Ultimate++ 2017.2. It is unclear if the error is triggered by some code I wrote even if it shows up in that file. In the past I compiled the same program on linux using an older version of Ultimate++ and it compiled without problems.
Regards,
Gio


The problem will be around here:

/home/pi/MyApps/StatusDetector/AggiungiComm.cpp:149:1:

Can you show us a couple of lines around it? Or maybe the whole file, if possible.

Re: Function.h: "expression cannot be used as a function" [message #49365 is a reply to message #49360] Wed, 31 January 2018 19:14 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Gate (or what you assigned to it) is supposed to return bool. In your case it returns void.

Regards,
Novo
Re: Function.h: "expression cannot be used as a function" [message #49377 is a reply to message #49362] Thu, 01 February 2018 10:47 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
mirek wrote on Wed, 31 January 2018 18:46

The problem will be around here:

/home/pi/MyApps/StatusDetector/AggiungiComm.cpp:149:1:

Can you show us a couple of lines around it? Or maybe the whole file, if possible.



This is the whole file. The line numbers differ from those in the log because I removed the comments. In the original file the line number 149 is the last line of the file and is blank.

#include "AggiungiComm.h"

AggiungiComm::AggiungiComm(MLav _mlav, char tipo)
{
	String macchina = _mlav.GetMacchina();
	CtrlLayoutOKCancel(*this, t_("Selezionare commessa e pezzatura"));
	Add(strCommPezz.LeftPosZ(16, 148).TopPosZ(12, 19));
	btnTrova <<= THISBACK1(ScanCommessa, macchina);
	listaMetri <<= THISBACK(CambioPezzatura);
	DisableFields();
	strMacchina = macchina;
	ok.Disable();
	btnTrova.Ok();
	if (tipo == 'B')
	{
		ok.Enable();
		ok.Ok();
		btnTrova.Normal().Disable();
		strCommPezz <<= AsString(_mlav.lav_in_corso.COMM) + AsString(_mlav.lav_in_corso.FASE) + "1" ;
		ScanCommessa(macchina);
	}
}

void AggiungiComm::ScanCommessa(String macchina)
{
	if (SplittaComm() > 0)
	{
		ok.Enable();
		ok.Ok();
		btnTrova.Normal().Disable();
	} else {
		PromptOK(t_("ATTENZIONE: commessa non trovata, effettuare di nuovo lo scan"));
		CleanFields();
		strMacchina = macchina;
	}
}

void AggiungiComm::CleanFields()
{
	strLav3A <<= Null;
	strLav3B <<= Null;
	strLav3C <<= Null;
	strLav3D <<= Null;
	strLav3Dbis <<= Null;
	strMacchina <<= Null;
	strCommPezz <<= Null;
	listaMetri.Reset();
	strCommPezz.SetFocus();
}

void AggiungiComm::DisableFields()
{
	strLav3A.Disable();
	strLav3B.Disable();
	strLav3C.Disable();
	strLav3D.Disable();
	strLav3Dbis.Disable();
	strMacchina.Disable();
	strCommPezz.SetFocus();
}

int AggiungiComm::SplittaComm()
{
	String ingresso = this->strCommPezz.GetData();
    WString pulita = (WString)TrimBoth(ingresso);
	pulita = pulita.Left(pulita.GetLength() - 1);
	WString comm = pulita.Left(pulita.GetLength() - 2);
	WString fas = pulita.Right(2);
	strLav3A = comm;
	strLav3B = fas;
	strLav3C = db_data.ContaBobFatte(AsString(comm), AsString(fas)) + 1;
	strLav3D = NULL;
	strLav3Dbis = NULL;
	int esiste_comm = db_data.ControllaCommessa(AsString(comm));
	if (esiste_comm > 0)
	{
		if (fas == (WString)"90")
		{
			InserisciPezzature(AsString(comm), AsString(fas));
		}
		else {
			vcodbob.resize(1);
			vmtbob.resize(1);
			std::fill(vcodbob.begin(), vcodbob.end(), "");
			std::fill(vmtbob.begin(), vmtbob.end(), 0);
			listaMetri = 0;
		}
	}
	return esiste_comm;
}

void AggiungiComm::InserisciPezzature(String commessa, String fase)
{
	std::vector<PEZZE_BOB> lista = db_data.TrovaPezzature(commessa, fase);
	size_t dimensione = lista.size();
	vcodbob.resize(dimensione);
	vmtbob.resize(dimensione);
	int m = 0;
	for (size_t i=0; i<lista.size(); i++)
	{
		int num_bob = lista[i].PEZZE.N_BOB;
		int k = 0;
		for(int j = 0; j < num_bob; j++)
		{
			if (AsString(lista[i].PEZZE.BOB) == "777")
				listaMetri.Set(m, m, t_(" Pezz. non prevista"));
			else
				listaMetri.Set(m, m, ( AsString(lista[i].PEZZE.MT) + "m - N: " + AsString(k+1) + " di " + AsString(num_bob)));
			vcodbob[m] = lista[i].PEZZE.BOB;
			vmtbob[m] = lista[i].PEZZE.MT;
			if (k<lista[i].fatte) { listaMetri.DisableCase(m); }
			k++;
			m++;
		}
		k = 0;
	}
	listaMetri = m -1;
	strLav3D.MaxLen(3);
	strLav3D <<= "777" ;
	strLav3Dbis = 0 ;
}

void AggiungiComm::CambioPezzatura()
{
	strLav3D.MaxLen(3);
	strLav3D <<= vcodbob[listaMetri] ;
	strLav3Dbis = vmtbob[listaMetri] ;
}

Re: Function.h: "expression cannot be used as a function" [message #49378 is a reply to message #49365] Thu, 01 February 2018 10:51 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Novo wrote on Wed, 31 January 2018 19:14
Gate (or what you assigned to it) is supposed to return bool. In your case it returns void.


This is not clear to me: Gate is in Function.h (Core library of U++).
Re: Function.h: "expression cannot be used as a function" [message #49379 is a reply to message #49378] Thu, 01 February 2018 11:16 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello Giorgio,

Quote:

This is not clear to me: Gate is in Function.h (Core library of U++).


Because compiler is tracing back the error to its source. Event/Gate/Function are templates. Event and Gate are aliases for specialized Function templates. Basically, compiler has to go back to their declarations (in function.h) to inform you that it cannot instantiate them with the parameters you provided.

As Novo pointed out, there is probably an ill-defined Event/Gate/Function (or CALLBACK) in your code. Check your callbacks and verify their signatures (i.e., if they are taking correct parameters, returning the expected value types or just void.)

First check:
	btnTrova <<= THISBACK1(ScanCommessa, macchina);
	listaMetri <<= THISBACK(CambioPezzatura);


Are these callbacks defined correctly?
Then check other callbacks. E.g. look into StatusDetector.h, AggiungiComm.h (if you defined some callback there).

Best regards,
Oblivion


[Updated on: Thu, 01 February 2018 11:51]

Report message to a moderator

Re: Function.h: "expression cannot be used as a function" [message #49381 is a reply to message #49379] Thu, 01 February 2018 14:13 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Oblivion wrote on Thu, 01 February 2018 11:16

Are these callbacks defined correctly?
Then check other callbacks. E.g. look into StatusDetector.h, AggiungiComm.h (if you defined some callback there).


I think they are defined correctly (the code on Windows compiles and works), but to be on the safe side I commented every and each callback in the application and the problem is still there... maybe gcc is too picky?
Re: Function.h: "expression cannot be used as a function" [message #49382 is a reply to message #49381] Thu, 01 February 2018 15:01 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Then it seems that maybe you are accidentally assigning an expression to a callback (Gate/Event/Function); You need to find it.
GCC will give you the same error in such cases.

E.g. A simple example:

Event<> event;

event << 2 * 2; // Will give you the exact same error 



Best regards,

Oblivion


[Updated on: Thu, 01 February 2018 15:07]

Report message to a moderator

Re: Function.h: "expression cannot be used as a function" [message #49383 is a reply to message #49382] Thu, 01 February 2018 16:21 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Well, finally I found the problem. I have a bunch of assignment like this:

strLav3D <<= vcodbob[listaMetri];


Now I changed the using .SetData:

strLav3D.SetData(vcodbob[listaMetri]);


And the program compiles. Weird thing, on Windows it compiles in any case. Furthermore, about 6 months ago the same application compiled with no problem on Linux, maybe tere was an older gcc version.

Thanks to all.
Re: Function.h: "expression cannot be used as a function" [message #49384 is a reply to message #49383] Thu, 01 February 2018 16:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
What is the declaration of vcoddob?

<<= should work, so this definitely warrants further examination...

Mirek
Re: Function.h: "expression cannot be used as a function" [message #49385 is a reply to message #49384] Thu, 01 February 2018 16:29 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
mirek wrote on Thu, 01 February 2018 16:25
What is the declaration of vcoddob?


std::vector<String> vcodbob;


But also there were things as simple as:

strLav3D <<= "777" ;

Re: Function.h: "expression cannot be used as a function" [message #49386 is a reply to message #49385] Thu, 01 February 2018 16:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Giorgio wrote on Thu, 01 February 2018 16:29
mirek wrote on Thu, 01 February 2018 16:25
What is the declaration of vcoddob?


std::vector<String> vcodbob;


But also there were things as simple as:

strLav3D <<= "777" ;



And what exectly is your compiler? (gcc --version)
Re: Function.h: "expression cannot be used as a function" [message #49387 is a reply to message #49386] Thu, 01 February 2018 16:37 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
mirek wrote on Thu, 01 February 2018 16:34

And what exectly is your compiler? (gcc --version)


Gcc (Raspbian 4.9.2-10) 4.9.2
Re: Function.h: "expression cannot be used as a function" [message #49388 is a reply to message #49387] Thu, 01 February 2018 17:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Giorgio wrote on Thu, 01 February 2018 16:37
mirek wrote on Thu, 01 February 2018 16:34

And what exectly is your compiler? (gcc --version)


Gcc (Raspbian 4.9.2-10) 4.9.2


That is quite old, but should work.

Can you compile theide?

BTW, off-topic: What raspberry variant are you using? I have got PI2, I wanted to do some tests with that and it is crashing way to often for any serious work. Probably overheating.
Re: Function.h: "expression cannot be used as a function" [message #49389 is a reply to message #49388] Thu, 01 February 2018 18:05 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
mirek wrote on Thu, 01 February 2018 17:43
Giorgio wrote on Thu, 01 February 2018 16:37
mirek wrote on Thu, 01 February 2018 16:34

And what exectly is your compiler? (gcc --version)


Gcc (Raspbian 4.9.2-10) 4.9.2


That is quite old, but should work.


I did an apt update / apt upgrade a couple of days ago, so it should be the latest available for Raspbian.

mirek wrote on Thu, 01 February 2018 17:43

Can you compile theide?


Yes, it takes ages but it compiles; I made all the tests using theide on Raspbian.

mirek wrote on Thu, 01 February 2018 17:43

BTW, off-topic: What raspberry variant are you using? I have got PI2, I wanted to do some tests with that and it is crashing way to often for any serious work. Probably overheating.


I have a Raspberry Pi 3 Model B, slow in compiling but it succeeds, lightweight applications works well (this will be tested on a manufacturing environment, working 24/24 5 days a week).
Previous Topic: I've been using FindFile wrong all these years
Next Topic: Vector<T>::Set(int i, T&& x) proposal
Goto Forum:
  


Current Time: Thu Mar 28 20:56:31 CET 2024

Total time taken to generate the page: 0.00848 seconds