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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:26:16+00:00 2026-05-26T06:26:16+00:00

Getting some really confusing errors and not sure exactly why. Here is my code:

  • 0

Getting some really confusing errors and not sure exactly why. Here is my code:

//=====================WORKS=======================
TradingBook::TradingBook(const char* yieldCurvePath, const char* bondPath)
{
//...Some stuff
    BaseBond* tradingBook[bondCount];

    for (int i=0; i < bondCount; i++)
    {
        tradingBook[i] = new CouponBond(bonds[i]);

        printf("Bond: %s\n"
           "  Price: %.3f\n"
           "  DV01: %.3f\n"
           "  Risk: %.3f\n", tradingBook[i]->getID(), tradingBook[i]->getPrice(), tradingBook[i]->getDV01(), tradingBook[i]->getRisk());
    }
}

//=================DOESNT WORK======================
//Gives Error: base operand of ‘->’ has non-pointer type ‘BaseBond’
void TradingBook::runAnalytics()
{
    for (int i=0; i < bondCount; i++)
    {
        tradingBook[i]->calcPrice(tradingBook[i]->getYield());
        tradingBook[i]->calcDV01();
        tradingBook[i]->calcRisk();

        printf("Bond: %s\n"
               "  Price: %.3f\n"
               "  DV01: %.3f\n"
               "  Risk: %.3f\n", tradingBook[i]->getID(), tradingBook[i]->getPrice(), tradingBook[i]->getDV01(), tradingBook[i]->getRisk());
    }
}

I get the error base operand of ‘->’ has non-pointer type ‘BaseBond’ at every instance of ->, but only in the runAnalytics() method. tradingBook is a public class variable. Why would it give me an error in the bottom method but not the constructor? I don’t get it.

I also tried changing all the tradingBook[i]->method() to tradingBook[i].method() in the 2nd method, but it gives me a segmentation fault so I figured that isn’t right. Can anyone help me clear up my confusion?

In case it is needed, here is the header file for TradingBook:

class TradingBook
{
    public:
        TradingBook(const char* yieldCurvePath, const char* bondPath);
        double getBenchmarkYield(short bPeriods) const;

        BaseBond* tradingBook;
        int treasuryCount;
        Treasury* yieldCurve;
        int bondCount;
        void runAnalytics();

};

BaseBond is an abstract class. It’s children are CouponBond and ZeroCouponBond. tradingBook[i] is filled with both types. Here is the header for BaseBond:

class BaseBond{
  public:
    virtual double getPrice() = 0;
    virtual double getYield() = 0;
    virtual short getPeriods() = 0;
    virtual char* getID() = 0;
    virtual double getDV01() = 0;
    virtual double getRisk() = 0;
    virtual char* getRateType() = 0;
    virtual void calcPrice(double nyield) = 0;
    virtual double calcPriceR(double nyield) const = 0;
    virtual void calcDV01() = 0;
    virtual void calcRisk() = 0;


};

Thank you in advance, stackOverFlow!

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

    It because this:

    BaseBond* tradingBook[bondCount];
    

    in the constructor constructs a scoped variable that hides tradingBook. change that whole line to:

    tradingBook = new BaseBond*[bondCount];
    

    and the line

    BaseBond* tradingBook;
    

    in the header to

    BaseBond** tradingBook;
    

    and it should work.

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

Sidebar

Related Questions

I'm getting some really wierd linking errors from a class I wrote. I am
I am getting some errors thrown in my code when I open a Windows
What are some options for getting really fast 'Find in Files' searching in VIM?
I am interested in getting some Python code talking to some Ruby code on
I'm getting some confusing results around myCustom.ashx handler. If i visit the handler via
I'm just starting a new project and I am getting some really weird stuff
really quick question does php 5 still support include_once because I am getting some
I'm getting some really weird issues with the Django admin application. I'm running everything
So I've written the class below, and it works, but we are getting some
I'm getting some strange, intermittent, data aborts (< 5% of the time) in some

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.