- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 3
- Posts with Upvotes
- 3
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
- Interests
- Nana C++ Library
8 Posted Topics
![]() | Re: In this situation, it can't be avoided. But why does the situation exist? I change your code like this. [CODE] void operate_fn2(A * p) { B * b = dynamic_cast<B*>(p); if(b) b->fn2(); } int main() { A *a1, *a2; a1 = new B; a2 = new C; // downcasting here … |
Re: I think you should make a method for printing a publication. [CODE] class Publication { public: //Publication doesn't know about what data of subclass should be printed virtual void print(std::ostream& os) const { os<<isbn<<title; } }; std::ostream& operator<<(std::ostream &os, const Publication &pub) { pub.print(os); return out; } class Book: public … | |
Re: [CODE] Test.keydata[4]= { 1, 2, 3, 4}; [/CODE] This is a list-initializer used for initialization. You should... [CODE] int main() { for(int i = 0; i < 4; ++i) Test.keydata[i] = i + 1; } [/CODE] | |
Re: [CODE]std::cout<<int(b[i]);[/CODE] It means output b[i] as an integer. If b[i] could not converse to int, it causes a compile-error. In C language, if b[i] is not a integer type, the output dose not make sense [CODE] std::cout<<b[i]; [/CODE] It outputs the b[i] by its own type. [CODE] char c = … | |
Re: [CODE] #include <fstream> #include <vector> #include <algorithm> #include <iterator> int main(void) { using namespace std; ifstream ifs("data.txt"); vector<int> vec; copy(istream_iterator<int>(ifs), istream_iterator<int>(), back_inserter(vec)); sort(vec.begin(), vec.end()); copy(vec.begin(), vec.end(), ostream_iterator<int>(cout, "\n")); } [/CODE] | |
Re: The node should like this [CODE] struct Node { Book * book; Node * next; }; [/CODE] And create a class as a manipulator for the list. [CODE] class book_list { public: book_list() :head_(0), tail_(0) {} template<typename _Book> void push_back(const _Book & book) { Node * pn = new Node; … | |
Re: [CODE] STARTUPINFO siStartupInfo = {0}; siStartupInfo.cb = sizeof sif; siStartupInfo.dwFlags = STARTF_USESHOWWINDOW; siStartupInfo.wShowWindow = SW_NORMAL; PROCESS_INFORMATION piProcessInfo = {0}; [/CODE] And an alternate method is recommended by using ShellExecute/ShellExecuted if you don't want to manipulate the new process. | |
Re: STL is a useful library for data structure and algorithms. Please learn it. refer to [url]http://www.sgi.com/tech/stl[/url] for study. |
The End.