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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:57:12+00:00 2026-05-19T01:57:12+00:00

I was wondering if there was a way to include a data member which

  • 0

I was wondering if there was a way to include a data member which is an array of unfixed size.

The function initModulation will create an int array of size M and a Complex array of size M. (Complex is another class and is made up of a real component and imaginary component).

The function modulate will need to be able to access these two arrays. These two arrays go out of scope after the init Modulation function is called. To avoid this, I would just make these two data members of the Modulator class, however I can’t do that because the array size depends on M.

class Modulator
{
    int M;
    double phase;
    std::string mapping;

public:
    void initModulation(int M, double phase, std::string mapping);
    double* modulate(int *input,int inputlength,int complexFlag);
};

Any ideas around this?

Thanks,
Minh

  • 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-19T01:57:12+00:00Added an answer on May 19, 2026 at 1:57 am
    1. Don’t write initialization functions without very special circumstances; construct with the constructor.

    2. The arrays are logical part of the class data, since they are used for modulation, and that’s what instances of the class do. So you should have them as members.

    3. You were planning to create arrays of unknown-at-compile-time size, right? How does it matter whether you’re storing them as members of the class or not? Either way, you have the information about M at this point, and use it accordingly.

    4. But you shouldn’t be allocating your own arrays, anyway. Use std::vector. After all, you’re smart enough to use std::string for text data, so…

    5. Why would you use an int for a parameter that’s supposedly some sort of “flag”? C++ has a real boolean type, called bool. Use it.

    6. For the input and output of modulation, again, use vectors.

    7. Having a class with a member function whose name aligns with the class name is suspicious. Many languages support the idea of a “callable” object and C++ is among them. In C++, we spell this functionality “operator()“.

    Thus:

    class Modulator
    {
        std::vector<int> int_data;
        std::vector<Complex> complex_data;
        double phase;
        std::string mapping;
    
        public:
        Modulator(int M, double phase, std::string mapping): 
        int_data(M), complex_data(M), phase(phase), mapping(mapping) {}
    
        std::vector<double> operator()(const std::vector<int>& input, bool is_complex);
    };
    

    Welcome to modern C++. 🙂

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

Sidebar

Related Questions

I was wondering if there is way to open another page using a Modal
I think I understand unit testing. But I was wondering: is there a way
Just wondering if there is any way (in C) to get the contents of
I'm wondering if there's a way to do what I can do below with
I was wondering if there was a way to get at the raw HTTP
I was wondering if there is any way to escape a CDATA end token
I was wondering if there is a way for a network of N participants
I was wondering if there was a way to use find_by_sql within a named_scope.
I was wondering if there is some way to name or rename a property
I was wondering if there was a way to tell if an instance of

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.