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 6895141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:52:15+00:00 2026-05-27T06:52:15+00:00

In a data-structure, how do you insert a function? struct Student_info { std::string name;

  • 0

In a data-structure, how do you insert a function?

struct Student_info {
std::string name;
double midterm, final;
unsigned int& counter;
std::vector<double> homework;
double overall = grade(students[counter]);
};

always get this type of error:-

a. “variable” was not declared in this code.

b. “Student_info::counter” cannot appear in a constant-expression.

c. an array reference cannot appear in a constant-expression.

d. a function call cannot appear in a constant-expression

edit:-
oopps, i mean student_info contain in a vector, wait, why that’s info needed anyway… Dx

oh, and btw, this is from Accelerated C++, a book obviously, and I’m trying to answer one of its exercise, then I need to know this part, not found any on the book Dx

the question is 4-6. Rewrite the Student_info structure to calculate the grades immediately and store only the final grade.

  • 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-27T06:52:16+00:00Added an answer on May 27, 2026 at 6:52 am

    You can NOT dynamically insert a function into a structure.

    You can declare a structure that has a method()

    struct Student_info
    {
        void doDomethingToStudent()
        {
             // Manipulate the object here.
        }
        // STUFF
    };
    

    Also you can not initialize member like above.

    double overall = grade(students[counter]);
    

    Here you need to create constructor that will initialize members.

    struct Student_info
    {
        Student_info(std::string& studentName, unsigned int& externalCounter)
            : name(studentName)
            , midterm(0)
            , final(0)
            , counter(externalCounter)
            , homework()
    
            // It is not clear if overall is a normal memeber
            // Or a static member of the class
            , overall(grade(students[counter]))
        {}
        // STUFF
    };
    int main()
    {
        unsigned int counter   = 0;
        Student_info bob("Bob", counter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to perform update/insert simultaneously changing structure of incoming data. Think about Shops
I have a data structure that represents C# code like this: class Namespace: string
What is the best data-structure for doing following operation quickly Insert Find. Thanks Avinash
in any dictionary data structure there is an add_to_ds function which receives the data
What is a good data structure for storing phone numbers in database fields? I'm
I want a data structure that will allow querying how many items in last
I'm writing a data structure in C# (a priority queue using a fibonacci heap
Given a data structure (e.g. a hash of hashes), what's the clean/recommended way to
I have the following data structure (a list of lists) [ ['4', '21', '1',
Are there any heap data structure implementations out there, fibonacci, binary, or binomial? Reference:

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.