Error when trying to run a macro


I am trying to run this macro (taken from the root tutorial)

int myMacro(int k = 0) 
	cout << "The input parameter was " << k << endl;
	return k;
$ root

which is saved in the macro directory.
This is the error I encounter

Warning: catmyMacro.cxxintmyMacro  Syntax error?? D:\root_v5.34.36\macros\myMacro.cpp(2)
Error: Missing one of '*&,;=():}' expected at or after line 9.
Error: Unexpected end of file (G__fgetvarname():2) D:\root_v5.34.36\macros\myMacro.cpp(9)
*** Interpreter error recovered ***

This is my first macro, and I’m not sure what I’m doing wrong.
Thank you.

What did you type after ‘root’? Typically one do:

$ root
root [0] .x macroFileName.C


$ root macroFileName.C


I got that error after typing

.x myMacro.cpp

however, after trying

$root myMacro.cpp

I’v received

Error: Invalid type 'root' in declaration of 'myMacro' (tmpfile)(1)
Error: Invalid type 'root' in declaration of 'myMacro' (tmpfile)(1)
Error: Symbol root myMacro is not defined in current scope  (tmpfile)(1)
Error: Failed to evaluate root myMacro.cpp
*** Interpreter error recovered ***

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.