Hello,
I'm coming over to C++ from various basics and Java. In java we use separate files for each class to keep things neat. From what I've been able to find online it seems most C++ programs tend to keep a large number of classes in one file?
Also, let's say I would like to continue using one file per class. I currently have two files one is Line.cpp
And the other is main.cppCode:/** A line represented by its slope and y-intercept. */ class Line{ private: double mySlope; // the slope for this line double myYIntercept; // the y-intercept for this line ; public: Line(double slope, double yIntercept); ~Line(); double getSlope(); double getYIntercept(); double calculateY(double xVal); }; Line::Line(double slope, double yIntercept){ mySlope = 1.0; myYIntercept = 5.0; }; Line::~Line(){ //deconstructors do not accept arguments; } double Line::getSlope(){ return mySlope; }; double Line::getYIntercept(){ return myYIntercept; }; double Line::calculateY(double xVal){ return myYIntercept+(mySlope*xVal); };
Code:#include <iostream> int main (int argc, char * const argv[]) { std::cout << "Hello, World!\n"; return 0; }
What do I need to do so that I can declare new Line objects from my main program?
Thanks much,
Norehsa



LinkBack URL
About LinkBacks



