| | |
Classes
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>Wich do you consider being a good (affordable) compiler?
If you want an IDE then Dev-C++ is both free and good. The latest VC++ is only $99US for the standard edition, and Borland Builder is also $99US. Other options are Borland 5.5, which is free, or Comeau, probably the most conforming C++ compiler available (available for $50US).
>Would you have done this in a separate function or like I did in void print()?
It depends on your needs. What you have is a valid solution.
>Is there a way that I could alter this code so that I could write
>_ (1_2 <-- underneath eachother) in a relative simple way?
Unless something like this is acceptable then no:
>Is there a way to decrease the amount 'cout' in main but still have the possibility to write a destinctive name?
Can you rephrase that?
If you want an IDE then Dev-C++ is both free and good. The latest VC++ is only $99US for the standard edition, and Borland Builder is also $99US. Other options are Borland 5.5, which is free, or Comeau, probably the most conforming C++ compiler available (available for $50US).
>Would you have done this in a separate function or like I did in void print()?
It depends on your needs. What you have is a valid solution.
>Is there a way that I could alter this code so that I could write
>_ (1_2 <-- underneath eachother) in a relative simple way?
Unless something like this is acceptable then no:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { cout<< 1 <<"\n-\n"<< 2 <<endl; }
Can you rephrase that?
New members chased away this month: 4
>It depends on your needs. What you have is a valid solution
Then I'll leave it as it is.
>Unless something like this is acceptable then no:
Then I'll leave it as it is.
>Can you rephrase that?
Is there a way that when I write the operator I'm using in main it automatically writes a piece of code that explains what I'm going to do?
Like for instance when I type: c = fract1 * fract2; when executed, I would get automatically: Multiplied: - 1/2.
This way, I don't have to write cout's everytime I use a version of the operators.
Could this be done by writing the couts in the memberfunctions themselves?
I was thinking of grouping the text into one member function and depending on wich operator is used in main, call that particular piece of text?
Does that make sence :-|
Then I'll leave it as it is.
>Unless something like this is acceptable then no:
Then I'll leave it as it is.
>Can you rephrase that?
Is there a way that when I write the operator I'm using in main it automatically writes a piece of code that explains what I'm going to do?
Like for instance when I type: c = fract1 * fract2; when executed, I would get automatically: Multiplied: - 1/2.
This way, I don't have to write cout's everytime I use a version of the operators.
Could this be done by writing the couts in the memberfunctions themselves?
I was thinking of grouping the text into one member function and depending on wich operator is used in main, call that particular piece of text?
Does that make sence :-|
>Could this be done by writing the couts in the memberfunctions themselves?
Yes, though it's generally a better idea to avoid output in value producing member functions. A fraction class can be useful, and you may not want operator* to write to cout if you use the class in future projects.
Though a clean solution is to think polymorphically from the start:
Yes, though it's generally a better idea to avoid output in value producing member functions. A fraction class can be useful, and you may not want operator* to write to cout if you use the class in future projects.
Though a clean solution is to think polymorphically from the start:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class original_test { public: original_test ( int init ): data ( init ) {} public: virtual void print() const { cout<< data; } private: int data; }; class new_test: public original_test { public: new_test ( int init ): original_test ( init ) {} public: virtual void print() const { cout<<"Print: "; original_test::print(); } }; int main() { original_test t1 ( 10 ); new_test t2 ( 20 ); t1.print(); cout<<endl; t2.print(); cout<<endl; }
New members chased away this month: 4
Polymorphism, hmmm...polymorphism oh... yep found it --> Chapter 7 Section 4 :cheesy:
Guess It'll have to wait abit before I get there, but, great to hear there is a way to avoid so many cout's
Well, I'm starting Chapter 5 now, Templates, pointers and datastructures :!:
Thanks for the help Narue, going to read now about 40 pages, after that, it's exercise time again
Class solved.
Guess It'll have to wait abit before I get there, but, great to hear there is a way to avoid so many cout's
Well, I'm starting Chapter 5 now, Templates, pointers and datastructures :!:
Thanks for the help Narue, going to read now about 40 pages, after that, it's exercise time again
Class solved.
>Well, I'm starting Chapter 5 now, Templates, pointers and datastructures
Templates work too
:
Templates work too
: C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; struct noverbose { static void get() {} }; struct verbose { static void get() { cout<<"Get: "; } }; template <typename policy = noverbose> class test { public: test ( int init ): data ( init ) {} public: virtual void print() const { policy::get(); cout<< data; } private: int data; }; int main() { test<> t1 ( 10 ); test<verbose> t2 ( 20 ); t1.print(); cout<<endl; t2.print(); cout<<endl; }
New members chased away this month: 4
![]() |
Similar Threads
- need idea for project using classes and inheritance (C++)
- How do i do chat program using MFC (Microsoft Foundation Classes) and Visual Basic? (Visual Basic 4 / 5 / 6)
- Loading classes from a .jar file (Java)
- Help with Classes (C++)
- Understanding classes (C++)
- Working with objects of different Classes (Java)
- Classes (C++)
- Summer Classes (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: why won't my virtual area function work?
- Next Thread: minor problem with vectors and OOP
Views: 5565 | Replies: 44
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream input int integer java lazy lib linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






