- Forum
- Beginners
- error: default argument given for param
error: default argument given for parameter 1,2 and 3 of’int volume
This code is giving error: Default argument given for parameter 1,2 and 3 of’int volume’.
what is the possible problem with the code.
|
|
You can’t re-declare default arguments twice in the same scope. In practice, this means that default arguments (usually) appear only at the first declaration of the function.
|
|
The details are here:
http://en.cppreference.com/w/cpp/language/default_arguments
Topic archived. No new replies allowed.
Для меня это очень простая задача, и я не уверен, почему это создает мне проблемы. Я просто заставляю два класса-макета пытаться компилировать без какой-либо логики в своих методах с использованием уже предоставленных мне заголовков и объявлений. Честно говоря, это всего лишь работа по вырезке и вставке, и все же я все еще сталкивался с этим золотым самородком любви —
cbutton.cpp:11:44: error: default argument given for parameter 4 of ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.h:7:5: error: after previous specification in ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.cpp:11:44: error: default argument given for parameter 5 of ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.h:7:5: error: after previous specification in ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.cpp:19:41: error: default argument given for parameter 1 of ‘void cio::CButton::draw(int)’ [-fpermissive]
cbutton.h:11:10: error: after previous specification in ‘virtual void cio::CButton::draw(int)’ [-fpermissive]
cbutton.cpp:53:29: error: ‘virtual’ outside class declaration
Вот файлы, с которыми я работаю. Всем спасибо, как всегда!
#include "cfield.h"
namespace cio{
class CButton: public CField{
public:
CButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=C_BORDER_CHARS);
virtual ~CButton();
void draw(int rn=C_FULL_FRAME);
int edit();
bool editable()const;
void set(const void* str);
};
}#include "cbutton.h"
namespace cio {
CButton::CButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=C_BORDER_CHARS){
}
void CButton::draw(int rn=C_FULL_FRAME){
}
int CButton::edit(){
return 0;
}
bool CButton::editable()const {
return false;
}
void CButton::set(const void* str){
}
virtual CButton::~CButton(){
}
}
2
Решение
Вы указали аргумент по умолчанию в определении функции, в то время как они уже имели аргумент по умолчанию в объявлении класса. Вы можете объявить аргументы по умолчанию в объявлении класса или в определении функции, но не в обоих.
РЕДАКТИРОВАТЬ: Пропустил конец ваших ошибок: error: ‘virtual’ outside class declaration
, Это довольно очевидная ошибка компилятора: virtual
ключевые слова принадлежат объявлениям классов, а не определениям функций. Просто удалите его из определения вашего деструктора.
Исправленный источник:
namespace cio {
CButton::CButton(const char *Str, int Row, int Col,
bool Bordered, // No default parameter here,
const char* Border){ // here,
}
void CButton::draw(int rn){ // and here
}
CButton::~CButton(){ // No virtual keyword here
}
}
12
Другие решения
Вы не включаете параметр по умолчанию в определение своей функции, прототип — единственный, в который нужно включить значение по умолчанию.
#include "cbutton.h"
namespace cio {
CButton::CButton(const char *Str, int Row, int Col,
bool Bordered,
const char* Border){ //remove in def
}
void CButton::draw(int rn){
}
1
Вы не можете повторять аргументы по умолчанию при определении функции. Они принадлежат только на декларации. (Действительное правило не так просто, потому что определение также может быть определением, но вы поняли …)
0
ACTIONFENIX 3 / 3 / 2 Регистрация: 21.02.2015 Сообщений: 77 |
||||||||||||||||
1 |
||||||||||||||||
07.02.2017, 13:21. Показов 2811. Ответов 1 Метки нет (Все метки)
Не могу понять, почему выдает эту странную ошибку:
весь код прилагается:
__________________
0 |
Горбаг 184 / 176 / 57 Регистрация: 25.09.2014 Сообщений: 828 |
||||||||
07.02.2017, 13:33 |
2 |
|||||||
РешениеВо втором конструкторе у тебя так в cpp:
а должно быть так:
Добавлено через 2 минуты
1 |
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
qwewer0 opened this issue
Jan 27, 2020
· 76 comments
Closed
[BUG] Can’t compile Marlin 2.0.2
#16691
qwewer0 opened this issue
Jan 27, 2020
· 76 comments
Comments
Configuration.zip
VS Code terminal output
In file included from Marlinsrcmodule/stepper.h:47:0,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:701:0: warning: "enable_Z" redefined
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); Z4_enable(); }while(0)
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:142:0: note: this is the location of the previous definition
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
In file included from Marlinsrcmodule/stepper.h:47:0,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:702:0: warning: "disable_Z" redefined
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); Z4_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:143:0: note: this is the location of the previous definition
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:47:61: error: default argument given for parameter 1 of 'void manage_inactivity(bool)' [-fpermissive]
void manage_inactivity(const bool ignore_stepper_queue=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:47:6: note: previous specification in 'void manage_inactivity(bool)' here
void manage_inactivity(const bool ignore_stepper_queue=false);
^~~~~~~~~~~~~~~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 1 of 'void kill(const char*, const char*, bool)' [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in 'void kill(const char*, const char*, bool)' here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 2 of 'void kill(const char*, const char*, bool)' [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in 'void kill(const char*, const char*, bool)' here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 3 of 'void kill(const char*, const char*, bool)' [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in 'void kill(const char*, const char*, bool)' here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:69:43: error: default argument given for parameter 1 of 'void minkill(bool)' [-fpermissive]
void minkill(const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:326:6: note: previous specification in 'void minkill(bool)' here
void minkill(const bool steppers_off=false);
^~~~~~~
compilation terminated due to -fmax-errors=5.
*** [.piobuildSTM32F103RC_bigtree_512KsrcsrcMarlin.cpp.o] Error 1
Copy link
Contributor
Author
PlatformIO in MarlinCore.h underscores the «false» in these:
(47) — void manage_inactivity(const bool ignore_stepper_queue=false);
(68) — void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
(69) — void minkill(const bool steppers_off=false);
Copy link
Contributor
Author
Unable to compile Bugfix-2.0.x with this terminal output:
Marlinsrcgcodegcode.cpp: In static member function 'static void GcodeSuite::process_parsed_command(bool)':
Marlinsrcgcodegcode.cpp:335:16: error: 'G60' was not declared in this scope
case 60: G60(); break; // G60: save current position
^~~
Marlinsrcgcodegcode.cpp:335:16: note: suggested alternative: 'G10'
case 60: G60(); break; // G60: save current position
^~~
G10
Marlinsrcgcodegcode.cpp:336:16: error: 'G61' was not declared in this scope
case 61: G61(); break; // G61: Apply/restore saved coordinates.
^~~
Marlinsrcgcodegcode.cpp:336:16: note: suggested alternative: 'G11'
case 61: G61(); break; // G61: Apply/restore saved coordinates.
^~~
G11
*** [.piobuildSTM32F103RC_bigtree_512Ksrcsrcgcodegcode.cpp.o] Error 1
Copy link
Contributor
Author
By commenting out lines 335 and 336 in gcode.cpp I was able to compile Bugfix-2.0.x. The problem with 2.0.2 is still remain.
Can’t compile Marlin 2.0.2
VS Code terminal output
«`
Compiling .piobuildLPC1769srcsrccoreutility.cpp.o
In file included from Marlinsrcmodule/stepper.h:47,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:701: warning: «enable_Z» redefined
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); Z4_enable(); }while(0)
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:142: note: this is the location of the previous definition
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
In file included from Marlinsrcmodule/stepper.h:47,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:702: warning: «disable_Z» redefined
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); Z4_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:143: note: this is the location of the previous definition
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
Compiling .piobuildLPC1769srcsrcfeatureI2CPositionEncoder.cpp.o
Compiling .piobuildLPC1769srcsrcfeatureMax7219_Debug_LEDs.cpp.o
Compiling .piobuildLPC1769srcsrcfeaturebabystep.cpp.o
Compiling .piobuildLPC1769srcsrcfeaturebacklash.cpp.o
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:47:61: error: default argument given for parameter 1 of ‘void manage_inactivity(bool)’ [-fpermissive]
void manage_inactivity(const bool ignore_stepper_queue=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:47:6: note: previous specification in ‘void manage_inactivity(bool)’ here
void manage_inactivity(const bool ignore_stepper_queue=false);
^~~~~~~~~~~~~~~~~
Compiling .piobuildLPC1769srcsrcfeaturebaricuda.cpp.o
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 1 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 2 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 3 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:69:43: error: default argument given for parameter 1 of ‘void minkill(bool)’ [-fpermissive]
void minkill(const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:326:6: note: previous specification in ‘void minkill(bool)’ here
void minkill(const bool steppers_off=false);
^~~~~~~
compilation terminated due to -fmax-errors=5.
*** [.piobuildLPC1769srcsrcMarlin.cpp.o] Error 1
============================================================ [FAILED] Took 13.33 seconds ============================================================
Environment Status Duration
megaatmega2560 IGNORED
megaatmega1280 IGNORED
rambo IGNORED
FYSETC_F6_13 IGNORED
FYSETC_F6_14 IGNORED
sanguino_atmega644p IGNORED
sanguino_atmega1284p IGNORED
melzi IGNORED
melzi_optiboot IGNORED
at90usb1286_cdc IGNORED
at90usb1286_dfu IGNORED
DUE IGNORED
DUE_USB IGNORED
DUE_debug IGNORED
LPC1768 IGNORED
LPC1769 FAILED 00:00:13.333
even with zero changes it fails to compile..
Issue is it has marlin.h, marlin.cpp and marlincore.h, marlincore.cpp… cant have both sets
Then you get the G60/G61 errors also…
Same here:
VS Code terminal output
«`
Compiling .pio/build/STM32F103RC_bigtree/src/src/core/utility.cpp.o
In file included from Marlin/src/module/stepper.h:47:0,
from Marlin/src/Marlin.cpp:37:
Marlin/src/module/stepper/indirection.h:701:0: warning: «enable_Z» redefined
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); Z4_enable(); }while(0)
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:142:0: note: this is the location of the previous definition
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
In file included from Marlin/src/module/stepper.h:47:0,
from Marlin/src/Marlin.cpp:37:
Marlin/src/module/stepper/indirection.h:702:0: warning: «disable_Z» redefined
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); Z4_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:143:0: note: this is the location of the previous definition
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from Marlin/src/lcd/ultralcd.h:40:0,
from Marlin/src/Marlin.cpp:34:
Marlin/src/lcd/../MarlinCore.h:45:1: error: default argument given for parameter 1 of ‘void idle(bool)’ [-fpermissive]
);
^
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:41:6: note: previous specification in ‘void idle(bool)’ here
void idle(
^~~~
In file included from Marlin/src/lcd/ultralcd.h:40:0,
from Marlin/src/Marlin.cpp:34:
Marlin/src/lcd/../MarlinCore.h:47:61: error: default argument given for parameter 1 of ‘void manage_inactivity(bool)’ [-fpermissive]
void manage_inactivity(const bool ignore_stepper_queue=false);
^
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:47:6: note: previous specification in ‘void manage_inactivity(bool)’ here
void manage_inactivity(const bool ignore_stepper_queue=false);
^~~~~~~~~~~~~~~~~
In file included from Marlin/src/lcd/ultralcd.h:40:0,
from Marlin/src/Marlin.cpp:34:
Marlin/src/lcd/../MarlinCore.h:68:106: error: default argument given for parameter 1 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlin/src/lcd/ultralcd.h:40:0,
from Marlin/src/Marlin.cpp:34:
Marlin/src/lcd/../MarlinCore.h:68:106: error: default argument given for parameter 2 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlin/src/lcd/ultralcd.h:40:0,
from Marlin/src/Marlin.cpp:34:
Marlin/src/lcd/../MarlinCore.h:68:106: error: default argument given for parameter 3 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from Marlin/src/Marlin.cpp:31:0:
Marlin/src/Marlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
compilation terminated due to -fmax-errors=5.
*** [.pio/build/STM32F103RC_bigtree/src/src/Marlin.cpp.o] Error 1
=============================================================== [FAILED] Took 190.07 seconds ===============================================================
Environment Status Duration
megaatmega2560 IGNORED
megaatmega1280 IGNORED
rambo IGNORED
FYSETC_F6_13 IGNORED
FYSETC_F6_14 IGNORED
sanguino_atmega644p IGNORED
sanguino_atmega1284p IGNORED
melzi IGNORED
melzi_optiboot IGNORED
at90usb1286_cdc IGNORED
at90usb1286_dfu IGNORED
DUE IGNORED
DUE_USB IGNORED
DUE_debug IGNORED
LPC1768 IGNORED
LPC1769 IGNORED
STM32F103RC IGNORED
STM32F103RC_fysetc IGNORED
STM32F103RC_bigtree FAILED 00:03:10.074
STM32F103RC_bigtree_USB IGNORED
STM32F103RC_bigtree_512K IGNORED
STM32F103RC_bigtree_512K_USB IGNORED
STM32F103RE IGNORED
STM32F103RE_bigtree IGNORED
STM32F103RE_bigtree_USB IGNORED
STM32F4 IGNORED
STM32F7 IGNORED
ARMED IGNORED
STM32F103VE_GTM32 IGNORED
STM32F103VE_longer IGNORED
mks_robin_mini IGNORED
mks_robin_nano IGNORED
mks_robin IGNORED
mks_robin_pro IGNORED
mks_robin_lite IGNORED
mks_robin_lite3 IGNORED
jgaurora_a5s_a1 IGNORED
STM32F103CB_malyan IGNORED
chitu_f103 IGNORED
STM32F401VE_STEVAL IGNORED
FLYF407ZG IGNORED
FYSETC_S6 IGNORED
STM32F407VE_black IGNORED
BIGTREE_SKR_PRO IGNORED
BIGTREE_GTR_V1_0 IGNORED
BIGTREE_BTT002 IGNORED
teensy31 IGNORED
teensy35 IGNORED
esp32 IGNORED
linux_native IGNORED
SAMD51_grandcentral_m4 IGNORED
rumba32_f446ve IGNORED
mks_rumba32 IGNORED
include_tree IGNORED
========================================================== 1 failed, 0 succeeded in 00:03:10.074 ==========================================================
#define STRING_DISTRIBUTION_DATE «2020-01-27»
Can you compile after deleting files Marlin/src/Marlin.h and Marlin/src/Marlin.cpp ?
Copy link
Contributor
Author
Can you compile after deleting files src/Marlin.h and src/Marlin.cpp ?
What files exactly?
Magic Works. Whats the reason behind this . I deleted two files and after that compile the firmware. And its successful
If you use Marlin 2.0.2 release, downloaded before commit ec79034 and you cannot simply update to latest bugfix-2.0.x (wich was fixed with commit 8bd6b60), I can confirm that 2.0.2 relase compiles if you delete files Marlin/src/Marlin.h and Marlin/src/Marlin.cpp and also delete lines 335 and 336 in file Marlin/src/gcode/gcode.cpp
Deleting lines 335 and 336 in file Marlin/src/gcode/gcode.cpp and also deleting files Marlin/src/Marlin.h and Marlin/src/Marlin.cpp doesn’t solve the problem. I cannot compile with VSCode:
Marlin/src/_Marlin.cpp:31:10: fatal error: Marlin.h: No such file or directory
Did you really delete the files?
I also have a compilation problem , skr e3 mini
Same error as @spooky79 (SKR Mini E3 v1.2)
EDIT: It does compile with changes suggested by DerAndere1 … just not sure if that will break anything functionality wise?
VS Code terminal output
«`
In file included from Marlinsrcmodule/stepper.h:47:0,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:701:0: warning: «enable_Z» redefined
Compiling .piobuildSTM32F103RC_bigtree_512K_USBsrcsrcfeaturebacklash.cpp.o
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); Z4_enable(); }while(0)
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:142:0: note: this is the location of the previous definition
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
In file included from Marlinsrcmodule/stepper.h:47:0,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:702:0: warning: «disable_Z» redefined
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); Z4_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:143:0: note: this is the location of the previous definition
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:45:1: error: default argument given for parameter 1 of ‘void idle(bool)’ [-fpermissive]
);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:41:6: note: previous specification in ‘void idle(bool)’ here
void idle(
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:47:61: error: default argument given for parameter 1 of ‘void manage_inactivity(bool)’ [-fpermissive]
void manage_inactivity(const bool ignore_stepper_queue=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:47:6: note: previous specification in ‘void manage_inactivity(bool)’ here
void manage_inactivity(const bool ignore_stepper_queue=false);
^~~~~~~~~~~~~~~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 1 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 2 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 3 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
compilation terminated due to -fmax-errors=5.
*** [.piobuildSTM32F103RC_bigtree_512K_USBsrcsrcMarlin.cpp.o] Error 1
Did you really delete the files?
I confirm deleting those files solves the problem. Before I just changed files name.
I get also this compile error:
Marlin/src/feature/pause.cpp: In function 'bool unload_filament(const float&, bool, PauseMode)':
Marlin/src/feature/pause.cpp:355:20: error: 'FILAMENT_UNLOAD_PURGE_FEEDRATE' was not declared in this scope
(FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Marlin/src/feature/pause.cpp:355:20: note: suggested alternative: 'FILAMENT_UNLOAD_PURGE_RETRACT'
(FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILAMENT_UNLOAD_PURGE_RETRACT
I get also this compile error:
Marlin/src/feature/pause.cpp: In function ‘bool unload_filament(const float&, bool, PauseMode)’:
Marlin/src/feature/pause.cpp:355:20: error: ‘FILAMENT_UNLOAD_PURGE_FEEDRATE’ was not declared in this scope
(FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Marlin/src/feature/pause.cpp:355:20: note: suggested alternative: ‘FILAMENT_UNLOAD_PURGE_RETRACT’
(FILAMENT_UNLOAD_PURGE_FEEDRATE) * mix_multiplier);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILAMENT_UNLOAD_PURGE_RETRACT
I’ve been having to add this line in for awhile now, not sure why it’s missing:
#define FILAMENT_UNLOAD_PURGE_FEEDRATE 25 // (mm/s) feedrate to purge before unload
You need to use the configs that are found in the Marlin folder and edit these to your needs. Don’t use the ones found in the config/example folder. They don’t seem to be updated for 2.0.2
I just added this line to my configuration_adv.h file:
#define FILAMENT_UNLOAD_PURGE_FEEDRATE 10 // (mm/s) Unload purge filament feedrate. This can be pretty fast.
Now it compiles without errors!
You need to use the configs that are found in the Marlin folder and edit these to your needs. Don’t use the ones found in the config/example folder. They don’t seem to be updated for 2.0.2
manually configured the same problem
VS Code terminal output
«`
In file included from Marlinsrcmodule/stepper.h:47:0,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:701:0: warning: «enable_Z» redefined
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); Z4_enable(); }while(0)
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:142:0: note: this is the location of the previous definition
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
In file included from Marlinsrcmodule/stepper.h:47:0,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:702:0: warning: «disable_Z» redefined
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); Z4_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:143:0: note: this is the location of the previous definition
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
Compiling .piobuildSTM32F103RC_bigtree_512Ksrcsrcfeaturebedlevelablabl.cpp.o
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:45:1: error: default argument given for parameter 1 of ‘void idle(bool)’ [-fpermissive]
);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:41:6: note: previous specification in ‘void idle(bool)’ here
void idle(
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:47:61: error: default argument given for parameter 1 of ‘void manage_inactivity(bool)’ [-fpermissive]
void manage_inactivity(const bool ignore_stepper_queue=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:47:6: note: previous specification in ‘void manage_inactivity(bool)’ here
void manage_inactivity(const bool ignore_stepper_queue=false);
^~~~~~~~~~~~~~~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 1 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 2 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40:0,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 3 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:0:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
compilation terminated due to -fmax-errors=5.
If I modify Marlin 2.0.2, according to comment #16691 (comment) and replace the configs with an example config from https://github.com/MarlinFirmware/Configurations, I can compile sucessfully using the Arduino IDE.
I thought we were encouraged to use VSCode / PlatformIO ? More to the point the repository probably needs to be fixed if it can’t be compiled because of extra files present.
Update:
- The G60/61 bug in the OP has been patched.
Download Marlin 2.0.2 again.
There is still the issue with Marlin.h and Marlin.cpp.
To solve this you must delete the files
.../Marlin/src/Marlin.h
and
.../Marlin/src/Marlin.cpp
Do not rename nor copy them in a newly created folder within Marlin.
You should now be able to compile successfully. In my case with «STM32F103RC_bigtree_512K»
If you still have an issue then it’s best you post your configs:
Configuration.h
Configuration_adv.h
platformio.ini
Copy link
Contributor
Author
20.01.28. Still can’t compile 2.0.2. Will wait for official fix.
Post your config files so we can take a look.
Copy link
Contributor
Author
See it on the first comment.
Copy link
Contributor
Author
I usually don’t update to Bugfix because of the potential bugs in that, that’s why I waited for 2.0.2, but it still got one in.
why? that will be a frozen copy as soon its out and 2.0.x will move on
but your call
will close this one
I just cloned the latest Bugfix and my configs, it just worked. Don’t know why wouldn’t work for you.
What did you do to make it compile. I cloned a fresh copy, used the Ender 3 configuration files and it does not build.
Even with default config, not using Ender 3 configs does not compile
Copy link
Contributor
Author
If this is still a problem, then we need to reopen it.
will close this one
Should it compile with the default config files included in 2.0.x? If not, can you provide yours for testing?
Copy link
Contributor
Author
Try Bugfix-2.0.x, my configs are in the first comment.
Should it compile with the default config files included in 2.0.x? If not, can you provide yours for testing?
Try Bugfix-2.0.x, my configs are in the first comment.
Should it compile with the default config files included in 2.0.x? If not, can you provide yours for testing?
It does compile fine! I assumed 2.0.x is ahead of 2.0.2 but it is not. All good but maybe make sure future releases can be at least built. That is the point of a release in my opinion.
I also just did a fresh build from bugfix-2.0.x and I get the exact same errors as noted here: #16691 (comment)
I also just did a fresh build from bugfix-2.0.x and I get the exact same errors as noted here: #16691 (comment)
e4eaf32 does compile fine for me with PlatformIO
The Bugfix-2.0.x is sound and this thread need not be reopened.
For those still having a problem should open a new issue.
Copy link
Contributor
Author
True
The Bugfix-2.0.x is sound and this thread need not be reopened.
For those still having a issue should open a new issue.
why? that will be a frozen copy as soon its out and 2.0.x will move on
A frozen version (that works) is exactly what most people need. As long as there is a stable released version, people should only need to use the bugfix branch if they actually need a bug fix or want to help out by testing the latest code. I feel it is incorrect to unconditionally encourage all users to use the unstable bugfix branch.
@sjasonsmith I agree completely as the situation with the philosophy used by Marlin is a bit unorthodox and strays from usual practices IMO.
I think @thinkyhead should chime in on this and give his thoughts on the matter as I’ve also mentioned it in the past as well. Don’t know however if the subject of discussion is placed here correctly.
I feel it is incorrect to unconditionally encourage all users to use the unstable bugfix branch.
i did not mean it like that, its more that people think the highest mumbers is the latest,
but yes common sense should always be applied and people should try both bugfix 2.0.x and 2.0.2 (or whatever the highest number is)
not sure if this one is related but it might be
#16709
still get the same faults with 2.0.2
default argument given for parameter 1 of 'void manage_inactivity(bool)' [-fpermissive]
default argument given for parameter 1 of 'void kill(const char*, const char*, bool)' [-fpermissive]
default argument given for parameter 1 of 'void minkill(bool)' [-fpermissive]
going over 2 bugfix as a temporary solution as commented over here.
«`
Compiling .piobuildLPC1768srcsrcfeaturebedlevelublubl.cpp.o
In file included from Marlinsrcmodule/stepper.h:47,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:701: warning: «enable_Z» redefined
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); Z4_enable(); }while(0)
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:142: note: this is the location of the previous definition
#define enable_Z() do{ Z_enable(); Z2_enable(); Z3_enable(); }while(0)
In file included from Marlinsrcmodule/stepper.h:47,
from MarlinsrcMarlin.cpp:37:
Marlinsrcmodule/stepper/indirection.h:702: warning: «disable_Z» redefined
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); Z4_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:143: note: this is the location of the previous definition
#define disable_Z() do{ Z_disable(); Z2_disable(); Z3_disable(); CBI(axis_known_position, Z_AXIS); }while(0)
Compiling .piobuildLPC1768srcsrcfeaturebedlevelublubl_G29.cpp.o
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:45:1: error: default argument given for parameter 1 of ‘void idle(bool)’ [-fpermissive]
);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:41:6: note: previous specification in ‘void idle(bool)’ here
void idle(
^~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:47:61: error: default argument given for parameter 1 of ‘void manage_inactivity(bool)’ [-fpermissive]
void manage_inactivity(const bool ignore_stepper_queue=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:47:6: note: previous specification in ‘void manage_inactivity(bool)’ here
void manage_inactivity(const bool ignore_stepper_queue=false);
^~~~~~~~~~~~~~~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 1 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 2 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
In file included from Marlinsrclcd/ultralcd.h:40,
from MarlinsrcMarlin.cpp:34:
Marlinsrclcd/../MarlinCore.h:68:106: error: default argument given for parameter 3 of ‘void kill(const char*, const char*, bool)’ [-fpermissive]
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^
In file included from MarlinsrcMarlin.cpp:31:
MarlinsrcMarlin.h:325:6: note: previous specification in ‘void kill(const char*, const char*, bool)’ here
void kill(PGM_P const lcd_error=nullptr, PGM_P const lcd_component=nullptr, const bool steppers_off=false);
^~~~
compilation terminated due to -fmax-errors=5.
*** [.piobuildLPC1768srcsrcMarlin.cpp.o] Error 1
======================================================================== [FAILED] Took 5.21 seconds ========================================================================
Environment Status Duration
megaatmega2560 IGNORED
megaatmega1280 IGNORED
rambo IGNORED
FYSETC_F6_13 IGNORED
FYSETC_F6_14 IGNORED
sanguino_atmega644p IGNORED
sanguino_atmega1284p IGNORED
melzi IGNORED
melzi_optiboot IGNORED
at90usb1286_cdc IGNORED
at90usb1286_dfu IGNORED
DUE IGNORED
DUE_USB IGNORED
DUE_debug IGNORED
LPC1768 FAILED 00:00:05.211
</details>
Failed, downloaded again this morning. So where's the old versions?
You are using an outdated version of Marlin firmware which will cause the errors you are witnessing.
You are using an outdated version of Marlin firmware which will cause the errors you are witnessing.
2.0.2 downloaded from https://marlinfw.org/meta/download/ is an old version? I don’t think so, unless they aren’t keeping the website updated. Got any more info?
Now Marlin 2.0.1 compiled just fine. I had a copy of it around from some of the other printers.
Ah right, I missed that skimming over this monster. I’ll stick with 2.0.1 for now, I don’t feel like messing around with a nightly and a mod on these machines as they are in production.
Thanks!
Sorry about that. There was a merge problem that left some old files in place instead of deleting them! It is fixed now. Just re-download 2.0.2.
@thinkyhead You got 8.6k forks. I am not quite innocent with my own repos, but then, I have nowhere as many users. Are you aware that force-pushing branches or changing tags causes havoc for all clones of a repository? Like me, I now have to delete the 2.0.2 tag, otherwise, I would never see which commit you have tagged now after the fix.
I’ve noticed before that you have been force-pushing on release, that’s bad git practice on a public repository.
In this current case, as things have been done, you should probably still throw a 2.0.3 release tag.
On another note, have you thought about using the new (https://github.com/MarlinFirmware/Configurations) as a submodule in (https://github.com/MarlinFirmware/Marlin)? I know that there are no «perfect» solutions to version-dependeny between not-quite-loosely coupled projects using git alone, but right now, I think this will give everyone a headache, once a change in Marlin causes a cascade into Configurations, automated or manual, done by you — thanks for that — it becomes unnecessarily hard for anyone to figure out which commit of either repo belongs to the other, until the next release tag is attached. Am I stating myself clear or should I elaborate more on this?
So thanks for this great software, the war that broke out here over a troubled release, and those strange suggestions to «just» switch to unstable, should raise some eyebrows over what the QA for releases actually is. I’d say, gathering bug reports on a release version is fine, but then you can be brave enough to admit and assign a new release shortly after, if there’s something broken — moving the tag makes many even more miserable, and in history, it becomes a riddle what the issue and PR discussions where all about in the first place
@thinkyhead BTW : the config directory now is not empty, again… another merge fail? #16724
I this current case, as things have been done, you should probably still throw a 2.0.3 release tag.
That would be my expectation as well.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Об ошибках и решениях с параметрами по умолчанию
Программа ошибок
#include <iostream>
using namespace std;
static int count = 0;
void print_str(char *str, int n, int &ref = count);
int main()
{
char *str = (char *)"Hello World!";
print_str(str, 0);
cout << endl;
print_str(str, 1);
cout << endl;
print_str(str, 1);
return 0;
}
void print_str(char *str, int n, int &ref = count)
{
++ref;
if (n)
{
for (int i = 0; i < ref; i++)
{
cout << str << endl;
}
}
else
{
cout << str << endl;
}
}
2. Результаты компиляции следующие:
1.printstr.cpp:14:50: error: default argument given for parameter 3 of 'void print_str(char*, int, int&)'
[-fpermissive]
void print_str(char *str, int n, int &ref = count)
^
1.printstr.cpp:4:6: note: previous specification in 'void print_str(char*, int, int&)' here
void print_str(char *str, int n, int &ref = count);
3. Причина ошибки:
Параметр по умолчанию может быть указан только один раз. Только значение по умолчанию указанного параметра в объявлении и определении функции. Если оба указаны как незаконные;
Компилятор Причина, по которой эта ситуация незаконна: если разные значения по умолчанию указаны в декларации и определении, компилятор не сможет определить, какое значение используется в качестве значения по умолчанию. параметров.
4. После модификации:
5. Компиляция и бежать гладко
|
|
|
[!] Как относитесь к модерированию на этом форуме? Выскажите свое мнение здесь
Функции с параметрами по-умолчанию
, Компилятор GCC
- Подписаться на тему
- Сообщить другу
- Скачать/распечатать тему
|
|
Junior Рейтинг (т): 1 |
Компилятор GCC. int f(int a = 0); int main() { std::cout<<f(2); return 0; } int f(int a = 0) { return a; } Компилятор ругаеться: Цитата
error: after previous specification in `int f(int)’ line 1 Что это значит? Неужели в GCC нельзя использовать параметры по-умолчанию? |
archimed7592 |
|
параметр по умолчанию нужно указывать только в объявлении ф-ции… |
ccop |
|
Junior Рейтинг (т): 1 |
Спасибо, будем знать |
LPBOY |
|
Цитата archimed7592 @ 03.04.07, 18:40 параметр по умолчанию нужно указывать только в объявлении ф-ции… Можно и в определении, но только если определение находится выше вызова функции. Ошибка в примере в том, что агумент по умолчанию задан более одного раза. int f(int a); int f(int a = 0) // ok { return a; } int main() { std::cout << f(); return 0; } int f(int a = 0); int f(int a = 0); // error int f(int a) { return a; } int f(int a, int b = 1, int c = 2); //int f(int a = 3, int b = 1, int c = 2); // error int f(int a = 3, int b, int c) // ok { return a + b + c; } |
archimed7592 |
|
смысла большого указывать в определении не вижу… либо определение сразу является объявлением (вся реализация в хэдере), либо указывать только в объявлении (когда реализация в отдельном модуле)… |
LPBOY |
|
Цитата archimed7592 @ 04.04.07, 13:37 смысла большого указывать в определении не вижу…
Насчет смысла не знаю, я написал из-за чего ругается компилятор. Сообщение отредактировано: LPBOY — 04.04.07, 14:27 |
0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
0 пользователей:
- Предыдущая тема
- C/C++: Прочее
- Следующая тема
[ Script execution time: 0,0305 ] [ 16 queries used ] [ Generated: 9.02.23, 13:16 GMT ]
Я думаю, что прохождение по ссылке здесь не имеет особого смысла.
Одной из причин прохождения по ссылке было бы использовать параметр как возвращаемое значение (так что измените ввод), но тогда значение по умолчанию не имеет большого смысла.
Другой причиной перехода по ссылке может быть некоторое улучшение производительности, чтобы не копировать все данные. Это не критично für cv :: Mat, так как в любом случае копируется только заголовок и поле данных по ссылке/указателю. Если вам нужно очень часто вызывать эту функцию, возможно, у вас может быть улучшение производительности, не копируя заголовок, но в этом случае вы не хотите иметь значение по умолчанию, которое все время создает новый cv :: Mat.
Поэтому мое решение вашей проблемы состояло бы в том, чтобы передать значение:
cv::Mat function(cv::Mat matrix = cv::Mat::eye(2,3, CV_32F))
{
return matrix;
}
int main()
{
std::cout << function() << "nn" ;
std::cout << function(cv::Mat::zeros(2,3, CV_32F)) << std::endl;
return 0;
}
дает мне этот вывод терминала как ожидаемый/ожидаемый:
[1, 0, 0;
0, 1, 0]
[0, 0, 0;
0, 0, 0]