problem with strings ND header file

I have this problem with strings and my constructor. MV C++ tells me that strings in the constructor (within the security class) of my security.cpp file are not recognized. if i delete the member "Type" from the constructor then the program works as expected. The security.h file appears working fine so i am not sure if the problem is there or in the .cpp file.
Any help is appreciated!!!

here is security.h:
#ifndef SECURITY_H
#define SECURITY_H
class Security
{private:
double p;
double c;
double d;
int e;
int t;

public:
Security();
Security(string Type,
double Price,
double Discount,
double Cashflow,
int Expiry);
};
#endif


and security.cpp:

#include "security.h"
#include <iostream>
#include <string>
using namespace std;

Security::Security()
{p=0;c=0;d=0;e=0;t=0;
}


Security::Security(string Type,
double Price,
double Discount,
double Cashflow,
int Expiry)
{ t=setType(Type);
p=Price;
c=Cashflow;
d=Discount;
e=Expiry;
};


int setType(string T)
{if (T == "bond")
{ return 1;}
else if (T=="stock")
{return 2;}
}
That's because there's no such primitive type as "string". There is int, and double, and float, and char, and others like that, but not string.

If you want to use some object of type "string" you must either define it yourself, or include something that defines it for you (e.g. a header file that defines something called "string"). You have not done this in security.h

Note that security.h gets copied wholesale into security.cpp where it is included. You then go on to define a std::string type two lines later, with #include <string> , but that's too late for where you try to use a string type in security.h
Last edited on
Thanks a lot for the info!!!
Topic archived. No new replies allowed.