I am just trying to get set up with some simple classes in C++. I am trying to create an Order type that takes in a price (double), quantity (int) and a style (std::string)
Here is my order.h
#ifndef ORDER_H
#define ORDER_H
#include <string>
#include <iostream>
class Order {
private:
double limit_price;
int quantity;
std::string style;
public:
Order();
Order(double price, int quantity, std::string style);
void print_price();
void print();
};
#endif
My implementation in order.cpp.
#include "order.h"
#include <iostream>
Order::Order(){
limit_price = 0;
quantity = 0;
style = "bid";
}
Order::Order(double price, int quantity, std::string style){
limit_price = price;
quantity = quantity;
style = style;
}
void Order::print_price(){
std::cout << "limit_price = " << limit_price << std::endl;
}
void Order::print(){
std::cout << style << " " << quantity << "@" << limit_price << std::endl;
}
And here is my simple test code.
#include "order.cpp"
#include <iostream>
#include <string>
int main(){
Order null_order = Order();
Order order = Order(12.3, 2, "bid");
null_order.print();
order.print();
return 0;
}
However, for a reason I don't understand, when I run I run my test file, instead of getting
bid 0@0
bid 2@12.3
As I would have expected, I get something like the following.
bid 0@0
-1722935952@12.3
Where the large negative number changes on each run.