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

  • SEARCH
  • Home
  • 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 8345809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:48:17+00:00 2026-06-09T06:48:17+00:00

In my main function I create an array of objects of a certain class

  • 0

In my main function I create an array of objects of a certain class “Menu”

And when I call a function I want to provide a pointer to that array.

Menu menu[2];
// Create menu [0], [1]
Function(POINTER_TO_ARRAY);

Question: What is the correct way to write the Function parameters?

I try:

Function(&menu);

and in Header file:

void Function(Menu *menu[]); // not working
error: Cannot convert parameter 1 from Menu(*)[2] to Menu *[]

void Function(Menu * menu); // not working
error: Cannot convert parameter 1 from Menu(*)[2] to Menu *[]

and I can’t come up with any other way to do this and I can’t find a solution to this particular problem.

Simply, I want to be able to access the Menu array within the function through a pointer. What are the difference in normal pointer to a pointer to an array?

  • 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-06-09T06:48:18+00:00Added an answer on June 9, 2026 at 6:48 am

    Declaration:

    void Function(Menu* a_menus); // Arrays decay to pointers.
    

    Invocation:

    Function(menu);
    

    However, you would need to inform Function() how many entries are in the array. As this is C++ suggest using std::array or std::vector which have knowledge of their size, beginning and end:

    std::vector<Menu> menus;
    menus.push_back(Menu("1"));
    menus.push_back(Menu("2"));
    
    Function(menus);
    
    void Function(const std::vector<Menu>& a_menus)
    {
        std::for_each(a_menus.begin(),
                      a_menus.end(),
                      [](const Menu& a_menu)
                      {
                          // Use a_menu
                      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a function that goes through an array of objects, and creates a
I am writing a template class for an array of objects, call it arrayobjclass,
I'm trying to create a class that has a map of keys -> function
Okay, I have an array in my Main Class that looks like this: objectArray:Array
I need to return an array of class objects from a function. I understand
Possible Duplicate: Can main function call itself in C++? I found this problem very
I have a main function in javascript that is function a() { some code
I have main.cpp (including main function) and func1.cpp, and I want to link these
In Winforms you just have the Main function and that's what runs first, but
I have a array of objects and wants to create an online invoice to

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.