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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:30:07+00:00 2026-06-01T02:30:07+00:00

I am trying to write some code to calculate dividend yields. I need to

  • 0

I am trying to write some code to calculate dividend yields. I need to calculate the dividend yield (dividend/stock_price) daily. Dividends are constant. Eventually, I will have to tie the stock price to a dynamic feed, but in the meantime the stock prices may be in their own map. I inserted the dividend amounts for each stock in the class constructor because it is less computationally cumbersome than using conditional statements in the members (i.e if stock = Apple, then dividend is X). I am getting the following error message starting at the ‘[‘ before the “AAPL”:

**error C2679: binary '[' : no operator found which takes a right-hand operand of type 'const 
char [5]' (or there is no acceptable conversion) c:\boost/unordered/unordered_map.hpp(415):  
could be 'double  &boost::unordered_map<K,T>::operator [](const FinModels::Instrument *const &)'
with 
     [
          K=const FinModels::Instrument *,
          T=double
      ]
      while trying to match the argument list '(DividendMap, const char [5])'**

Can anyone help me based on my brief code below and description? Is const Symbol* incorrect type for the key?

Also, if it’s bad convention to post the fixed map values in the constructor, please let me know what is better.

Header File

public:

typedef boost::unordered_map<const Symbol*, double> Dividend_Map;
typedef Dividend_Map::iterator Dividend_MapIterator;

private:
Dividend_Map p_dividend_map;

.CPP File

p_dividend_map["AAPL"] = 0.01;
p_dividend_map["BAC"] = 0.01;
p_dividend_map["C"] = 0.01;
  • 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-01T02:30:08+00:00Added an answer on June 1, 2026 at 2:30 am

    The key type for your map is a Symbol *, and you’re trying to stick a bunch of const char * into the map. This will not work unless Symbol is typedef‘d as char.

    Create a Symbol object out of each symbol you want to store in the map and then add the address of that to the map.

    Symbol appl("AAPL"); // assuming Symbol has a constructor taking a const char *
    
    p_dividend_map[&appl] = 0.01;
    

    In the example above, the lifetime of aapl must match its lifetime as a member of the map. If the lifetime of aapl expires you’ll have the map pointing to an invalid memory location.

    You may want to change the map to

    typedef boost::unordered_map<Symbol, double> Dividend_Map;
    

    Then use it as

    Symbol appl("AAPL");
    
    p_dividend_map[appl] = 0.01;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write some code that that will draw the line which
I'm trying to write some code to calculate a cumulative distribution function in matlab.
I'm trying to write some code that will take any object and convert it
I'm trying to write some code that various sites will embed, calling a script
I am trying to write some code that will function like google calendars quick
I'm trying to write some code which will highlight any text selected on a
I'm trying to write some code that will print out the dimensions of all
I am trying to write some code that will loop through a list and
I am trying to write some code which will open List1.txt and copy the
I'm trying to write some code to find a specific XmlNode object based on

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.