- Forum
- Beginners
- expression cannot be used as a function
expression cannot be used as a function
Hello,
I am exploring Mersenne Twister implementation to use it as a wrapped class that can be reused as a dll for other implementations like C#. I was trying this class and cannot figure out what is wrong. The code listed below and also available @ cpp.sh/4hte. I will appreciate any guidance help with fixing this class.
It gives me error
In member function ‘double Random::GenerateNext()’: 19:19: error: expression cannot be used as a function 20:2: warning: control reaches end of non-void function [-Wreturn-type]
|
|
Well, you have ponters, not objects, remember. You need to dereference pointers first.
Why do you use pointer semantic at all?
|
|
Last edited on
Topic archived. No new replies allowed.
#include <iarduino_Pressure_BMP.h> // Подключаем библиотеку для работы с датчиками BMP180 или BMP280
iarduino_Pressure_BMP sensor(0x76); // Создаём объект sensor для работы с датчиком адрес которого на шине I2C установлен по умолчанию.
#include "FastLED.h"
#define NUM_LEDS 114 // 4*7*4 +2 Количество светодиодов
#define COLOR_ORDER BRG // Порядок цвета для ленты
#define DATA_PIN 6 // Вывод для данных
#define BRI_PIN 3 // Вывод сенсора
CRGB leds[NUM_LEDS]; // Определение СД ленты
// 0,0,0,0
// 1,1,1,1
// 1 2 3 4 5 6 7 8 9 10111213141516171819202122232425262728
byte digits[12][28] = {{0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 0
{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1}, // Digit 1
{1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0}, // Digit 2
{1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}, // Digit 3
{1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1}, // Digit 4
{1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1}, // Digit 5
{1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 6
{0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1}, // Digit 7
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 8
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1}, // Digit 9 | Массив числе на 7 сегментах
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0}, // Digit *0
{0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0}}; // Digit C
// сигнальный провод подключен к 2 пину на Arduino
bool Dot = false; //состояние точек
int last_digit = 0;
// int ledColor = 0x0000FF; // Используемый цвет (in hex)
long ledColor = CRGB::DarkOrchid; // Используемый цвет (in hex)
//long ledColor = CRGB::MediumVioletRed;
//Случайные цвета
long ColorTable[16] = {
CRGB::Amethyst,
CRGB::Aqua,
CRGB::Blue,
CRGB::Chartreuse,
CRGB::DarkGreen,
CRGB::DarkMagenta,
CRGB::DarkOrange,
CRGB::DeepPink,
CRGB::Fuchsia,
CRGB::Gold,
CRGB::GreenYellow,
CRGB::LightCoral,
CRGB::Tomato,
CRGB::Salmon,
CRGB::Red,
CRGB::Orchid
};
void setup(){
Serial.begin(9600);
delay(1000);
sensor.begin(); // Инициируем работу с датчиком (начальная высота по умолчанию = 0 метров)
LEDS.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Выбор типа ленты
LEDS.setBrightness(55); // Установка яркости
}
// Convert temp to array needet for display
void TempToArray(){
// tmElements_t tm;
// RTC.read(tm);
// if (tm.Second != 27) {
// TempShow = false;
// return;
// }
/*
if (time.seconds !=20||time.seconds !=50){
TempShow = false;
return;
}
*/
/*
// TempShow = true;
// int t = RTC.temperature();
int t = sensor.temperature;
// int celsius = (t / 4.0) * 100;
int celsius = t;
*/
int celsius = sensor.temperature;
// Serial.print("Temp is: ");Serial.println(celsius);
// Serial.println(sensor.temperature);
Serial.println(celsius);
int cursor = 114; // last led number
leds[57]=0x000000;
leds[56]=0x000000;
for(int i=1;i<=4;i++){
int digit = celsius % 10; // get last digit in time
if (i==1){
Serial.print("Digit 4 is : ");Serial.print(digit);Serial.print(" ");
cursor = 86;
for(int k=0; k<=27;k++){
Serial.print(digits[11][k]);
if (digits[11][k]== 1){leds[cursor]=ledColor;}
else if (digits[11][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==2){
Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" ");
cursor =58;
for(int k=0; k<=27;k++){
Serial.print(digits[10][k]);
if (digits[10][k]== 1){leds[cursor]=ledColor;}
else if (digits[10][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==3){
Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" ");
cursor =28;
for(int k=0; k<=27;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
else if (i==4){
Serial.print("Digit 1 is : ");Serial.print(digit);Serial.print(" ");
cursor =0;
for(int k=0; k<=27;k++){
Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
Serial.println();
}
celsius /= 10;
};
};
void loop (){
TempToArray();
FastLED.show();
}
Я пытаюсь скомпилировать некоторый код (используя GCC 4.8.2) и получаю error: expression cannot be used as a function
,
Вот соответствующий код.
debug.h
// A macro for code which is not expected to be reached under valid assumptions
#if !defined(NDEBUG)
#define UNREACHABLE() do {
ERR("t! Unreachable reached: %s(%d)n", __FUNCTION__, __LINE__);
assert(false);
} while(0)
#else
#define UNREACHABLE() ERR("t! Unreachable reached: %s(%d)n", __FUNCTION__, __LINE__)
#endif
someFile.cpp (действительно важна только строка по умолчанию)
HLSLBlockEncoder::HLSLBlockEncoderStrategy HLSLBlockEncoder::GetStrategyFor(ShShaderOutput outputType)
{
switch (outputType)
{
case SH_HLSL9_OUTPUT: return ENCODE_LOOSE;
case SH_HLSL11_OUTPUT: return ENCODE_PACKED;
default: UNREACHABLE(); return ENCODE_PACKED;
}
}
Ошибка:
/.../debug.h:123:90: error: expression cannot be used as a function
#define UNREACHABLE() ERR("t! Unreachable reached: %s(%d)n", __FUNCTION__, __LINE__)
^
/.../someFile.cpp:217:16: note: in expansion of macro 'UNREACHABLE'
default: UNREACHABLE(); return ENCODE_PACKED;
^
Я пытаюсь понять, почему происходит ошибка. Смотря на этот вопрос Я подумал, что, возможно, проблема в том, что функция (HLSL …) использовалась в качестве переменной из-за __FUNCTION__
в макросе. Но согласно документация GCC: «GCC предоставляет три магические переменные, которые содержат имя текущей функции в виде строки», поэтому я не думаю, что это проблема. Есть другие идеи?
0
Решение
Обновление это с решением, которое я нашел.
Спасибо тем, кто сказал мне, чтобы расследовать ERR
Больше. Оказывается, было дублированное определение ERR
в другом заголовочном файле, который, кажется, вызывает мою ошибку. Изменение определения ERR
в debug.h чтобы избежать этого столкновения исправил мои проблемы. 🙂
0
Другие решения
Других решений пока нет …
Be careful, (x1-x2)^2
will not do an exponent of 2 here.
See http://www.cplusplus.com/reference/cmath/pow/.
Second, you probably forgot a +
in your expression:
int distanceFormula(int x1, int y1, int x2, int y2) {
double d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
return d;
}
The compiler error is because 2(y1-y2)
is invalid syntax.
In this case 2
(or perhaps (x1-x2)^2
) is the expression and (y1-y2)
is taken as a function call argument list; this grammar production is simply not allowed.
Compare the following form where a binary operator (*
) is introduced, which in turn makes the parser treat the subsequent (y1-y2)
as an expression (bounded by grouping parenthesis) and not a function call. While it wont do what is desired, as ^
is not exponentiation and the resulting equation is nonsense, it should parse and compile.
sqrt((x1-x2)^2*(y1-y2)^2)
c++ – Error: expression cannot be used as a function?
Related posts on c++ :
- c++ – How do I install SOIL (Simple OpenGL Image Loader)?
- c++ – Function cannot be referenced as it is a deleted function
- c++ – Error: Expression must have integral or unscoped enum type
- c++ – Argument list for class template is missing
- c++ – qualified-id in declaration before ( token
- Is it possible to decompile a C++ executable file
- c++ – Pointer to incomplete class type is not allowed
- c++ – error: use of deleted function
- c++ – Reference to non-static member function must be called
ArtjomsFC 0 / 0 / 0 Регистрация: 22.10.2019 Сообщений: 4 |
||||
1 |
||||
22.10.2019, 20:32. Показов 7586. Ответов 5 Метки function (Все метки)
Помогите решить проблемку. Не понимаю из-за чего ошибка. Вроде написал всё правильно.
__________________
0 |
6513 / 4646 / 1932 Регистрация: 02.02.2014 Сообщений: 12,478 |
|
22.10.2019, 20:48 |
2 |
Сообщение было отмечено ArtjomsFC как решение Решениефункция uzd описана с тремя аргументами, а вызов только с одним..
0 |
ArtjomsFC 0 / 0 / 0 Регистрация: 22.10.2019 Сообщений: 4 |
||||
23.10.2019, 14:31 [ТС] |
3 |
|||
Всё равно не работает
0 |
6513 / 4646 / 1932 Регистрация: 02.02.2014 Сообщений: 12,478 |
|
23.10.2019, 14:35 |
4 |
если uzd объявляется как функция, то ее не должно быть в списке переменных… ведь обяъвив ее как переменную, нельзя использовать ее в качестве функции. если совсем непонятно, то просто уберите uzd из списка переменных…
float y, x, k, atb, uzd, t;
0 |
hoggy 8719 / 4299 / 958 Регистрация: 15.11.2014 Сообщений: 9,744 |
||||
23.10.2019, 14:57 |
5 |
|||
float y, x, k, atb, uzd, t; заменить на:
0 |
7423 / 5018 / 2890 Регистрация: 18.12.2017 Сообщений: 15,694 |
|
23.10.2019, 15:06 |
6 |
ArtjomsFC, напишите условие задачи и сбросьте скрин формулы
0 |
hi,
by running the command: catkin_make -j1 —pkg rtabmap_ros , i got the following error. what is the solution???
Scanning dependencies of target rtabmap_ros
[ 57%] Building CXX object rtabmap_ros/CMakeFiles/rtabmap_ros.dir/src/MsgConversion.cpp.o
/home/masoumeh/catkin_ws4/src/rtabmap_ros/src/MsgConversion.cpp: In function ‘bool rtabmap_ros::convertScanMsg(const LaserScan&, const string&
, const string&, const ros::Time&, rtabmap::LaserScan&, tf::TransformListener&, double, bool)’:
/home/masoumeh/catkin_ws4/src/rtabmap_ros/src/MsgConversion.cpp:2105:81: error: expression cannot be used as a function
data = rtabmap::util3d::laserScan2dFromPointCloud(*pclScan, laserToOdom).data(); // put back in laser frame
^
/home/masoumeh/catkin_ws4/src/rtabmap_ros/src/MsgConversion.cpp:2113:81: error: expression cannot be used as a function
data = rtabmap::util3d::laserScan2dFromPointCloud(*pclScan, laserToOdom).data(); // put back in laser frame
^
/home/masoumeh/catkin_ws4/src/rtabmap_ros/src/MsgConversion.cpp: In function ‘bool rtabmap_ros::convertScan3dMsg(const PointCloud2&, const str
ing&, const string&, const ros::Time&, rtabmap::LaserScan&, tf::TransformListener&, double, int, float)’:
/home/masoumeh/catkin_ws4/src/rtabmap_ros/src/MsgConversion.cpp:2220:121: error: no matching function for call to ‘rtabmap::LaserScan::LaserSc
an(cv::Mat, int&, float&, rtabmap::Transform&)’
scan = rtabmap::LaserScan(rtabmap::util3d::laserScanFromPointCloud(*pclScan), maxPoints, maxRange, scanLocalTransform);
^
In file included from /usr/local/lib/rtabmap-0.20/../../include/rtabmap-0.20/rtabmap/core/SensorData.h:38:0,
from /usr/local/lib/rtabmap-0.20/../../include/rtabmap-0.20/rtabmap/core/Signature.h:42,
from /home/masoumeh/catkin_ws4/src/rtabmap_ros/include/rtabmap_ros/MsgConversion.h:47,
from /home/masoumeh/catkin_ws4/src/rtabmap_ros/src/MsgConversion.cpp:28:
/usr/local/lib/rtabmap-0.20/../../include/rtabmap-0.20/rtabmap/core/LaserScan.h:79:2: note: candidate: rtabmap::LaserScan::LaserScan(const cv:
:Mat&, rtabmap::LaserScan::Format, float, float, float, float, float, const rtabmap::Transform&)
LaserScan(const cv::Mat & data,
^
/usr/local/lib/rtabmap-0.20/../../include/rtabmap-0.20/rtabmap/core/LaserScan.h:79:2: note: candidate expects 8 arguments, 4 provided
/usr/local/lib/rtabmap-0.20/../../include/rtabmap-0.20/rtabmap/core/LaserScan.h:74:2: note: candidate: rtabmap::LaserScan::LaserScan(const cv:
:Mat&, int, float, rtabmap::LaserScan::Format, const rtabmap::Transform&)
LaserScan(const cv::Mat & data,
^
/usr/local/lib/rtabmap-0.20/../../include/rtabmap-0.20/rtabmap/core/LaserScan.h:74:2: note: no known conversion for argument 4 from ‘rtabmap
Home » U++ Library support » U++ Core » Function.h: «expression cannot be used as a function»
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
|||||||||
|
Goto Forum:
Current Time: Thu Feb 09 14:37:01 CET 2023
Total time taken to generate the page: 0.01277 seconds