|
Hey Andrew, you beat me to it!
Kevin
|
|
|
|
|
I assume that the three types of employee are in an inheritance hierarchy? In any case the best way to deal with these kinds of problem is to use the STL algorithms. Though, if you are new to programming, I appreciate there is a learning-curve here.
This is what I would do for a simple Employee class.
class Employee
{
public:
Employee(int id, const string& name) : _id(id), _name(name) {}
int id() const { return _id; }
string name() const { return _name; }
private:
int _id;
string _name;
};
// Function Object
class EmployeeEqualTo
{
public:
EmployeeEqualTo(int id) : _id(id) {}
// Criterion for equality
bool operator()(const Employee& employee) const
{ return employee.id() == _id; }
private:
int _id;
};
int _tmain(int argc, _TCHAR* argv[])
{
Employee e1 = Employee(1, "Peter");
Employee e2 = Employee(2, "Paul");
Employee e3 = Employee(3, "Helen");
vector<Employee> employees;
vector<Employee>::const_iterator it;
employees.push_back(e1);
employees.push_back(e2);
employees.push_back(e3);
// Find Employee with id = 2
it = find_if(employees.begin(), employees.end(), EmployeeEqualTo(2));
cout << "Name: " << it->name() << ", id: " << it->id() << "\n";
return 0;
}
If each Employee type uses the same id function, which I assume should be the case, the above should work as is, otherwise you can generalise this for the different employees and replace the <Employee> with <Employee*> to preserve polymorphism and take care to deallocate the Employee*.
If all this looks a bit mysterious, try reading the various STL tutorials on this site.
Oh, and you'll need to include a few headers
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
Kevin
|
|
|
|
|
Hi Everybody,
I want to use my .swf files(macromedia flash)
in my mfc app.
please help me,
best wishes,
thanks.
|
|
|
|
|
1. Go to this site: http://www.macromedia.com/software/flash/[^].
2. Buy the product.
3. Read the manual.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
Hi
Anyone used the ASTL library before in Visual C++? I am trying to use the ASTL library but am getting compile errors:
Compiling...
astl.cpp
c:\astl\astl.beta.2.0\include\dfa_matrix.h(108) : error C2955: 'char_traits' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\iosfwd(135) : see declaration of 'char_traits'
c:\code\astltry\astl.cpp(7) : see reference to class template instantiation 'DFA_matrix<class range<char,65,90="">,struct empty_tag>' being compiled
c:\astl\astl.beta.2.0\include\dfa_matrix.h(129) : fatal error C1903: unable to recover from previous error(s); stopping compilation
c:\code\astltry\astl.cpp(7) : see reference to class template instantiation 'DFA_matrix<class range<char,65,90="">,struct empty_tag>' being compiled
Error executing cl.exe.
astltry.exe - 2 error(s), 0 warning(s)
Please help.
Thanks a lot.
|
|
|
|
|
Hi
I am beginner learning C++ and using the Visual C++ compiler. How do I add class templates so that I can use it in Visual C++? Please highlight the steps.
Thanks a lot.
|
|
|
|
|
Hello,
The steps for success are the following:
1) Do a Google search
2) Apply the results
3) If errors are the result, search some more. (More Google, MSDN, CP,...)
4) When your head feels like exploding, ask here on CP
Until you tried steps 1 through 3, you should try doing your homework yourself...
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
I get compile errors when using iostream.h and fstream.h includes
while using .Net Pro 2003, but not VC++6.0 nor .Net Architect 2003.
How do I resolve this?
S. Thompson
|
|
|
|
|
try just typing #include < iostream > //without the *.h Thats working for me
humpa humpa
|
|
|
|
|
header files with *.h are not ansi standard, therefore they are not 100% supported in .net
|
|
|
|
|
Hi!
I created this class inside a dll file.
But how do I access it through my application?
It wasnt as easy as I thought it would be.
I tryed typing:
class __declspec(dllimport) CNetwork;
But that doesnt seam to work, just to create a whole new class called CNetwork. I couldnt access any of the functions I had in the class in the dll-file.
What to do?
Thanks
humpa humpa
|
|
|
|
|
use MFC Extention DLL and using AFX_EXT_CLASS macro export your class.
butbefore importing it in you application first include the header file which contain Class Declartion and the Lib file which contain runtime symbol for linking.
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
on your IDE's menu, click Project->Add Existing Item, and add the header file that way
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Newb question, im very new to c++, books im learning from say console app sould stay open with the message hit anykey to continue... but on my machine that dosent happen, after the program ends the console window closes so it is rather hard to see the resualts of the program. How do i keep it open with out adding some program lines to make it wait for some input after the rest of the progarm is done?
|
|
|
|
|
press ctrl+F5 if your using Visual Studio.
or add #include < Windows.h > among your header-files
and system("pause"); on the buttom of main function
humpa humpa
|
|
|
|
|
You can also use getch() which is defined in conio.h.
-John
|
|
|
|
|
Hi there,
I am developing a piece of code to grab images from Video files. Is the Video For Windows API still the way to go? As a side note, does anyone know how easy it is to grab images from DVDs?
AJ
|
|
|
|
|
I am trying to store top score (CString and int) (name and score) values to the registry
They are declared in the CMainFrame Class and initialized with the default values and in OnCreate from the stored values from the registry i debugged it and seen that they are okay till the end of the OnCreate function;
Used WriteProfileInt & WriteProfileString In OnClose and
Used GetProfileInt &GetProfileString In OnCreate
I wanted to update the values when the game is over and when game is over i post a message using PostMessage in The CView and in the handler function i use
((CMainFrame*)AfxGetApp())->m_strTopScore => now this value is null
((CMainFrame*)AfxGetApp())->m_iTopScore => now this value is 512
But As I said earlier the m_strTopScore was assigned a default value of "New Player"
and the m_iTopScore=0;
and when i try assign the m_strTopScore with new value
((CMainFrame*)AfxGetApp())->m_strTopScore="New String";
i get an ASSERT in line that says
_AFX_INLINE CStringData* CString::GetData() const
{ ASSERT(m_pchData != NULL); return ((CStringData*)m_pchData)-1; }
I used regedit and seen the stored default values in OnCreate i.e "NewPlayer" and 0
Why is the Value of 0 changed to 512 and NewPlayer to null
There is no place this variables are modified ??????? Any Ideas???????
|
|
|
|
|
Your question is a little confused.
Are you storing your data in your CFrameWnd derived class (CMainFrame) or in your CWinApp derived class.
AfxGetApp() returns a point to a CWinApp class and not your CMainFrame
You need to use AfxGetMainWnd to get a pointer to your CFrameWnd derived class.
Michael
CP Blog [^]
|
|
|
|
|
you should also be able to use CView::GetParentFrame()
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Sorry, I didn't mean GetParentFrame(), I meant GetParent(). This is a line of code that I use in one of my applications:
CMainFrame* pFrame = (CMainFrame*)GetParent();
then use
pFrame->m_strTopScore ;
make sure your variables are in the public section of your class definition for CMainFrame and make sure you #include "Mainfrm.h" in your view's .cpp file.
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Hi,
When I press a push button on one dialog box ,other dialog box or form should be displayed.How Can I do that?
Also please tell me how can we start an application B from other application A( eg. by pressing push button on application A).
Drushti
|
|
|
|
|
|
Thakyou Michael , it really helped in my application.
Drsuhti
|
|
|
|
|
to start another application, use ShellExecute()
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|