Newbie problem with classes

This is a discussion on Newbie problem with classes within the C++ Programming forums, part of the General Programming Boards category; Hi guys, I have found some sample code on the internet and was playing around with it in order to ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    3

    Newbie problem with classes

    Hi guys,

    I have found some sample code on the internet and was playing around with it in order to understand what it does, using CodeBlocks. The code is for the class is:

    Code:
    #ifndef EUROPEANOPTION_H_INCLUDED
    #define EUROPEANOPTION_H_INCLUDED
    
    #include <string>
    
    class EuropeanOption
    {
    private:
    
       void init();   // Initialise all default values
       void copy(const EuropeanOption& o2);
    
       // 'Kernel' functions for option calculations
       double CallPrice() const;
       double PutPrice() const;
       double CallDelta() const;
       double PutDelta() const;
    
    
    public:
       // Public member data for convenience only
       double r;      // Interest rate
       double sig;      // Volatility
       double K;      // Strike price
       double T;      // Expiry date
       double U;      // Current underlying price
       double b;      // Cost of carry
    
       string optType;   // Option name (call, put)
    
    };

    However, I am getting the following error on the last line: 'string' does not use name type.

    Am I calling the <string> class incorrectly? Also how does CodeBlocks add classes like string and math.h? Do I have to install them or are they already in CodeBlocks?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There is no such thing as a string. There is such a thing as a std::string, however.

    If you don't like typing std::string, and want to type string instead, then you can put
    Code:
    using namespace std;
    somewhere above that line, which essentially will tack on std:: in front of words that the compiler would otherwise complain about. (However, such a thing is generally frowned upon in .h files.)

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    fixed it, thanks!

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    one more question though, are there any statistical classes similar to math.h? I'm guessing I would probably have to write something myslef to get normal distribution p-values?

  5. #5
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    452
    Nope. But there is the gnu gsl library for numerical algo. I believe that lib is written in C though , so no classes. Math.h is also a C lib, so no classes either.
    Last edited by nimitzhunter; 02-07-2011 at 10:51 AM.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't know the contents of tr1 off the top of my head, but that was supposed to introduce some large quantity of statistical-type things. You may want to check there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with classes
    By xxmetalheadxx in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 07:02 AM
  2. Newbie question: Problem with malloc
    By Ikim in forum C Programming
    Replies: 2
    Last Post: 02-05-2006, 09:11 PM
  3. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 11:53 AM
  4. Problem with classes
    By crzy1 in forum C++ Programming
    Replies: 15
    Last Post: 02-24-2003, 09:38 PM
  5. newbie coding problem
    By rippascal in forum C++ Programming
    Replies: 10
    Last Post: 01-08-2002, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21