Ask Your Question

ROS not liking the way I try to access certain functions included in header file? [closed]

asked 2014-07-23 16:49:41 -0500

mysteriousmonkey29 gravatar image

updated 2014-07-24 11:28:17 -0500

Hello, I am currently trying to transform a C++ demo program I have for controlling a motor and laser scanner into a ROS node that will accomplish basically the same thing (but within ROS instead).

However, I am encountering some errors I don't know how to solve when compiling. ROS gives me an error for every line that tries to access a function in the header classes via an object and a dot seperator, but only when the function in question returns a value (no error for void functions). For example, in the cpp file I am trying to build, I have the lines

sickInterface.startSingleMeasurement(); //no error
success = sickInterface.getNextMeasurement(timestamp, scanData); //error: expected primary expression before ')' token

(I have successfully included the sickLMS115Interface.h file, and created the sickInterface object with the line

CSickLMS115Interface sickInterface;


However, ROS appears to not like the dot seperator, since I get the error "expected primary expression before ')' " on lines that attempt to access a non void header function via an object with arguments inputted, and the error "expected primary expression before '.' " on lines attempting to do the same thing, but without inputting arguments. The program compiled and functioned correctly before I tried to convert it to ROS. Any ideas what I'm doing wrong?

Here's my code (sorry its really long):

CMakeLists.txt: Actual node: Compilation errors:

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by mysteriousmonkey29
close date 2014-07-24 14:05:25.995550


can you post your code to get more info.

bvbdort gravatar image bvbdort  ( 2014-07-23 17:06:33 -0500 )edit

Yes, please provide more of your code, including your CMakeLists.txt and the full output of your compilation commad (including the command itself) that leads to these errors. Use or and provide the link(s) in your question if the code / output is long.

demmeln gravatar image demmeln  ( 2014-07-23 18:02:24 -0500 )edit
mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 11:27:13 -0500 )edit

Update: to control for errors that could have introduced by modifying the code, I created another cpp file in my same project with the exact original code (not yet modified by me). Original code: New compiler errors with original code:

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 12:53:30 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-07-24 13:14:17 -0500

ahendrix gravatar image

It looks like you have a type name shadowing a local variable name:

On line 211, there is a commented-out declaration of a scanData variable of type TSickLMS511ScanData

On line 219, you declare a variable named data with type scanData

Line 423 assumes that scanData is a variable

edit flag offensive delete link more


Ahh, I see. While combing the two programs I neglected to notice that one of the variables in one had the same name as a class in the other.

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 14:04:52 -0500 )edit

answered 2014-07-24 00:37:24 -0500

McMurdo gravatar image

What is the name of the class and that of the object?

Have you created an object before you try the members/member functions? This is one case where such a compiler error occurs.

ROS is not a compiler or IDE. So when you say, ROS doesn't like something, it can not be the case.

Essentially what you are doing when you say, "I converted it to ROS", is -

  1. Using a few ros functions/classes (with their prototypes in the headers),
  2. Linking in a few shared libraries with the definitions/implementations of these functions/classes.

From the point of view of c++, ROS is a library, and hence using ROS in a program can not create compilation errors that were not already present (except in the rarest of circumstances).

Have a great day.

edit flag offensive delete link more


I do create the object befor using it to access the functions, using the line CSickLMS115Interface sickInterface; However, I'll admit that I don't understand where the "CSick" part comes from, as the class imported is just called "sickLMS115Interface.h" without the sick CSick part (I am not the original author of this program.

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 11:56:02 -0500 )edit

And ok, maybe its not ROS per se that's messing up the compilation, it just feels that way because this code compiled before I tried to turn it into a ROS node. In all likelihood what's happening is that I screwed up something when I moved the code/modified it somewhat. So I'm really just trying to figure out what I screwed up. Thanks!

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-07-24 12:00:14 -0500 )edit

Question Tools

1 follower


Asked: 2014-07-23 16:49:41 -0500

Seen: 330 times

Last updated: Jul 24 '14