Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:02:38+00:00 2026-05-26T05:02:38+00:00

I have declared a helper function to a method of a class I declared

  • 0

I have declared a helper function to a method of a class I declared in a header file, and for some reason when I compile the source code file I get an error telling me that I declared a variable or field as void. I am not sure how to interpret this since my goal was for the function to be declared void.

The compiler errors are as follows:

k-d.cpp:10: error: variable or field ‘insert_Helper’ declared void
k-d.cpp:10: error: ‘node’ was not declared in this scope
k-d.cpp:10: error: ‘root’ was not declared in this scope
k-d.cpp:10: error: expected primary-expression before ‘*’ token
k-d.cpp:10: error: ‘o’ was not declared in this scope
k-d.cpp:10: error: expected primary-expression before ‘int’

The equivalent of line 10 in the code below is line 5.

The Source Code is as follows:

#include <iostream>
#include "k-d.h" //Defines the node and spot structs
using namespace std;

void insert_Helper(node *root, spot *o, int disc) {
    (...Some code here...)
}

void kdTree::insert(spot *o) {  //kdTree is a class outlined in k-d.h
    insert_Helper(root, o, 0); //root is defined in k-d.h
}

If anybody can spot anything that would cause the compiler to not see this as a function it would be greatly appreciated. Thanks!

P.S. I didn’t tag this as a kdtree post because I’m pretty sure the solution does not depend on that aspect of the code.

Update:

Here is k-d.h:

#ifndef K_D_H
#define K_D_H 

// Get a definition for NULL
#include <iostream>
#include <string>
#include "p2.h"
#include "dlist.h"

class kdTree {
    // OVERVIEW: contains a k-d tree of Objects

 public:

    // Operational methods

    bool isEmpty();
    // EFFECTS: returns true if tree is empy, false otherwise

    void insert(spot *o);
    // MODIFIES this
    // EFFECTS inserts o in the tree

    Dlist<spot> rangeFind(float xMax, float yMax);

    spot nearNeighbor(float X, float Y, string category);

    // Maintenance methods
    kdTree();                                   // ctor
    ~kdTree();                                  // dtor

 private:
    // A private type
    struct node {
        node *left;
        node *right;
        spot *o;
    };

    node   *root; // The pointer to the 1st node (NULL if none)
};

#endif 

And p2.h:

#ifndef P2_H
#define P2_H
#include <iostream>
#include <string>
using namespace std;

enum  {
    xCoor = 0,
    yCoor = 1
};

struct spot {
    float key[2];
    string name, category;
};

#endif 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:02:38+00:00Added an answer on May 26, 2026 at 5:02 am

    First off, you need to qualify kdTree::node because it’s declared as an inner struct. Secondly, you have to make insert_Helper a member of your class because node is private.

    Extra tip: remove the using directives from the .h files, and rather qualify all your usage of string, etc. Consider including that header in a lot of cpp files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my C# source code I may have declared integers as: int i =
I have following class with one static method: public class Helper { public static
I have some ASP.NET web services which all share a common helper class they
I have declared an enum in my server code, and would like my client
I have declared one variable in xslt, assigned some value to it but while
I have declared a class as class DCFrameListener : public FrameListener, public OIS::MouseListener, public
I have declared an external function with a GCC weak attribute in a .c
WorkAround: I have declared a class level Public static variable and initialized with a
i wonder if one should create a helper function in a class as a
Let's say I have a GridViewEx class declared which extends GridView . And inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.