I keep getting errors on 4 lines of code

Joined
Feb 10, 2023
Messages
2
Reaction score
1
/home/workspace/CppND-Route-Planning-Project/src/route_planner.cpp:22:36: error: qualified-id in declaration before '(' token
auto RoutePlanner::CalculateHValue (RouteModel::Node *node) {
^
/home/workspace/CppND-Route-Planning-Project/src/route_planner.cpp:34:33: error: qualified-id in declaration before '(' token
void RoutePlanner::AddNeighbors (RouteModel::Node *current_node) {
^
/home/workspace/CppND-Route-Planning-Project/src/route_planner.cpp:54:41: error: qualified-id in declaration before '(' token
RouteModel::Node *RoutePlanner::NextNode() {
^
/home/workspace/CppND-Route-Planning-Project/src/route_planner.cpp:108:1: error: expected '}' at end of input
}

These are the errors I've been getting and I've looked everywhere for an answer to what the error means and how to fix it.

auto RoutePlanner::CalculateHValue (RouteModel::Node *node) {
return node->distance(*end_node);
}

------------
void RoutePlanner::AddNeighbors (RouteModel::Node *current_node) {
current_node->FindNeighbors();
float n;
for (n : current_node-> neighbors){
n->parent=current_node;
n->h_value= CalculateHValue(n);
n->g_value= current_node->g_value + current_node ->distance(*n);
open_list.push_back(n);
n->visited = true;
}
}
---------
RouteModel::Node *RoutePlanner::NextNode() {
std::sort(open_list.begin(),open_list.end();
[](const float &first_n, float &second_n)
{
return first_n->h_value + first_n->g_value < second_n->h_value + second_n->g_value;
}
);

RouteModel::Node *Nodef = *(open_list.begin());
return Nodef;
----------------

and the last one is at the end of the code but it lines up with another { so i don't understand.
If anyone can help please let me know!! Thanks!!!
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
The first two errors are related to the definition of member functions of the RoutePlanner class. The error message is indicating that the definition of the functions is incorrect.

The issue is with the syntax of the member function definitions. In C++, the definition of a member function should be preceded by the class name, followed by the scope resolution operator :):), and then the function name. However, in your code, the auto keyword is appearing before the class name and the scope resolution operator. The correct syntax for the function definition should be:


Code:
float RoutePlanner::CalculateHValue(RouteModel::Node *node) {
  return node->distance(*end_node);
}

void RoutePlanner::AddNeighbors(RouteModel::Node *current_node) {
  current_node->FindNeighbors();
  float n;
  for (n : current_node->neighbors) {
    n->parent = current_node;
    n->h_value = CalculateHValue(n);
    n->g_value = current_node->g_value + current_node->distance(*n);
    open_list.push_back(n);
    n->visited = true;
  }
}

RouteModel::Node *RoutePlanner::NextNode() {
  std::sort(open_list.begin(), open_list.end(),
            [](const auto &first_n, auto &second_n) {
              return first_n->h_value + first_n->g_value <
                     second_n->h_value + second_n->g_value;
            });

  RouteModel::Node *Nodef = *(open_list.begin());
  return Nodef;
}

The last error message is indicating that there is an extra { at the end of the code and that it is expecting a } to match the opening brace. The solution for this error is to check your code for any extra braces and remove them if necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top