|
in the header file you need
vector<person> m_Staff;
void EmployeeDatabase::getEids(vector <int>&ids)
{ // Complete code.
ids = m_Staff;
}
void EmployeeDatabase::makePerson(string employeeName, int employeeID, double employeeShoeSize)
{//complete code.
Person p(employeeName, employeeID, employeeShoeSize); // this assumes a class called person with this constructor signature
m_Staff.push_back(p);
}
Now, for your search functions, do you want to do something like :
std::vector<person>::iterator it = m_Staff.begin();
for (; it != m_Staff.end(); ++it)
{
Person p = *it; // You dereference an iterator to get the object.
// Check if this person has the data you're looking for, and if so, return it.
}
// return some default value for item not found.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello everyone!
OK, look:
http://www.sulfurmidis.com/error.jpg
That's part of what I get when I try to compile my code in DOSBox using this command:
gpp tfc.cpp
The problem is that the code compiles really well on both Windows and Linux... Is this a problem with DJGPP and DOSBox, or am I doing something wrong? I downloaded everything that the Zip Picker from DJGPP's site told me, and then I unzipped it to a directory, set the DJGPP environment variable to "C:\DJGPP\DJGPP.ENV" (I also tried with forward slashes) and added the Bin directory to my PATH. Do I have to do something else? What do I do at this point? Thanks! Everyone who answers gets a free caramel candy!
PS: What's the difference between the GPP and G++ commands?
Sulfurik K. Nosferathus (Darth_Sulfur)
www.SulfurMidis.com
www.SulfurSoft.tk
http://www.BeepXtreme.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
|
Wow, I never thought I'd have to post this question here but after digging around I'm not totally certain what the best approach is.
Essentially, I'd like to write something like kiwisyslogD without the UI. Essentially I just need to watch in/out traffic on a NIC and log whether it's TCP/UDP/Etc the port and remote IP. If it's a web request I want to get the URL. I've seen tons of different examples that use WinPCap, Network Packet Drivers, Etc. They seem to have a lot of other stuff I don't need. This is only going to log to a file. It will never have a user interface nor will it do anything other than what I've just described. I only need Windows support and if I cannot support all flavors then 2K/XP/2K3 will have to do. I have no need/reason to log the traffic on the network. Just in/out on the host machine's NIC.
If I didn't have to reference a 3rd partly library I'd prefer that. What are the ideas and where do I begin? I've programmed in C/C++ but not in this nature before.
- Rex
Some assembly required.
Code-frog System Architects, Inc.
-- modified at 21:25 Saturday 10th September, 2005
|
|
|
|
|
I wrote some program about polymorphism but it is giving runtime error.
what i observe is it is not calling type cat speak() function
#include <iostream>
#include <string>
#include <conio>
using namespace std;
class Pet
{
public:
Pet(){}
virtual ~Pet(){}
virtual void speak();
inline void breath()
{cout<<"\nGASP "<<endl;}
};
void Pet::speak()
{
cout<<"\nGROW! "<<endl;
}
class rat:public Pet
{
public:
rat(){}
~rat(){}
void speak();
};
void rat::speak()
{ cout<<"\nRat noise "<<endl;}
class cat:public Pet
{
public:
cat(){}
~cat(){}
void speak();
};
void cat::speak()
{
cout<<"\nMeaw "<<endl;
}
/*void chorus(Pet pet,Pet *ptr,Pet &refptr)
{
pet.speak();
ptr->speak();
refptr.speak();
}*/
#define MAXCAP 50
int main()
{
int quit=0;
int choice;
int toalno;
Pet *ptr[MAXCAP];
int i=0;
while(quit==0&&i<MAXCAP)
{
cout<<"\nEneter(0) for Quit"<<endl;
cout<<"\nEneter(1) for rat"<<endl;
cout<<"\nEneter(2) for cat"<<endl;
cin>>choice;
if(choice==0)
{quit=1;}
else if(choice==1)
{ ptr[i++]=new rat;}
else if(choice==2)
{ptr[i++]==new cat;}
else
{cout<<"\nINVALID ENTRY"<<endl;}
}
toalno=i;
for(i=0;i<toalno;i++)
{
ptr[i]->speak();
}
getch();
return 0;
}
Regards
cnu...
-- modified at 13:06 Saturday 10th September, 2005
|
|
|
|
|
mcnu wrote:
{ptr[i++]==new cat;}
Did you mean = ?
BTW, I threw this into a compiler to see what was wrong and found it right away. Your compiler should give you a warning for mistakes like this, mine did.
Christian Graus - Microsoft MVP - C++
-- modified at 18:33 Sunday 11th September, 2005
|
|
|
|
|
I got that .But my compiler didn`t give any warnings for this.i am using Borland C++ 5.0
sorry for the wasting of your valueble time and
THANKS FOR THE HELP
Regards
cnu...
|
|
|
|
|
mcnu wrote:
sorry for the wasting of your valueble time
Not at all, glad to help. You should check your compiler warning settings, I'd have thought any half decent compiler would help you find little traps like this.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have the compiler Borland C++ 5.0 and Visual C++ 6.0.
which one is the best compiler . could you please suggest me .
Thank You
Regards
cnu...
|
|
|
|
|
I would guess VC6 because of the amount of online help you can get, but VC6 is really crappy, VC7 is tons better if you can get it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
is that same Visual Studio.net and VC++ 7.0
Regards
cnu...
|
|
|
|
|
Yes, .NET 2002 is VC 7.0. There is also 2003 and soon, 2005.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
VC7 is tons better if you can get it.
Make it VC 7.1, and download it for free here[^].
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Why the compiler complains about "'operator <<' is ambiguous" in statement like cout << I;. Is it ambiguous because it doesn't know which "<<" operator to call: the one in iostream and the one in code snippet below? If so I don't see any ambiguous exist!
#include <iostream>
#include <sstream>
#include <cstring>
using namespace std;
class IntArray
{
public:
enum { sz = 5 };
int i[sz];
IntArray() { memset(i, 0, sz* sizeof(*i)); }
int& operator[](int x)
{
return i[x];
}
friend ostream& operator<<(ostream& os, const IntArray& ia);
friend istream& operator>>(istream& is, IntArray& ia);
};
ostream& operator<<(ostream& os, const IntArray& ia)
{
for(int j = 0; j < ia.sz; j++)
{
os << ia.i[j];
if(j != ia.sz -1)
os << ", ";
}
os << endl;
return os;
}
istringstream& operator>>(istringstream& is, IntArray& ia)
{
for(int j = 0; j < ia.sz; j++)
is >> ia.i[j];
return is;
}
int main()
{
stringstream input("47 34 56 92 103");
IntArray I;
input >> I;
I[4] = -1;
cout << I;
}
|
|
|
|
|
I made some modifications in your code and it is working fine. i think objective of program is" reads input from user and get printed on screen" .that works fine and you need call operator "[]" like this:
I.operator[](-1);
#include <iostream>
#include <string>
#include <conio>
using namespace std;
class IntArray
{
public:
enum { sz = 5 };
int i[sz];
IntArray() { memset(i, 0, sz* sizeof(*i)); }
int& operator[](int x)
{
return i[x];
}
friend ostream&operator<<(ostream& os, const IntArray& ia);
friend istream&operator>>(istream& is, IntArray& ia);
};
ostream& operator<<(ostream& os, const IntArray& ia)
{
for(int j = 0; j < ia.sz; j++)
{
os << ia.i[j];
if(j != ia.sz -1)
os << ", ";
}
os << endl;
return os;
}
istream& operator>>(istream& is, IntArray& ia)
{
for(int j = 0; j < ia.sz; j++)
is >> ia.i[j];
return is;
}
int main()
{
/*stringistream input; */
IntArray I;
cin >> I;
//I[4] = -1; // Use overloaded operator[]
cout << I;
return 0;
}
Regards
cnu...
|
|
|
|
|
Thanks mcnu
But actually the original implementation isn't wrong, later I found when I made the definition of friend operator "<<" inside the class the codes compile smoothly!
I wonder why the compiler treated the operator "<<" definition outside class as another function!
|
|
|
|
|
Your Welcome
But it`s must be not giving error if it`s definition made inside the class or outside the class it must be work.
In my compiler it doesn`t giving error to the "<<"
operator definition
it is only giving error to the ">>" operator definition only
my compiler is Borland C++5.0
Regards
cnu...
|
|
|
|
|
|
I read your reference and i wonder why it is needing forward declaration.
anyway thanks to you because i got some new knowledge from you
Regards
cnu...
|
|
|
|
|
At first glance, this is an issue with Koenig lookup ( read my article ). VC6 is not very standards compliant. VC7 and onwards is a whole new world.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello everyone!
OK, I'm trying to port a C++ program that works under Borland's compiler over to Linux, using G++. When I try to compile it, I get a bunch of errors, most of them being based on this one:
'string' does not name a type
I've tried things like including string.h on all of my files and removing the .h extension, nothing worked. Then I thought that maybe string.h wasn't there for some reason, so I installed the libg++ RPM, that didn't work either... Today, I tried it on G++ for Windows, and guess what, I GOT THE EXACT SAME ERRORS! I tried the command-line parameter "IC:\MinGW\Include" to add that dir as an include directory, nope. Tried using Borland's include dir, nope. I asked Jesus to fix it for me, nope. (Just kidding...)
Anyone know what I can do next? Thanks!
Sulfurik K. Nosferathus (Darth_Sulfur)
www.SulfurMidis.com
www.SulfurSoft.tk
http://www.BeepXtreme.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
|
YAAAAAAY! It worked!
It compiled, but... how do I make an executable? I did this:
g++ -o tfc tfc.cpp
Like I do on Windows, and it generates a file called "tfc", like I specified. But how do I make it executable? I've tried that chmod 755 thing, but it still won't work... None of the tutorials on Google actually tell you how to do it... Could you? Thanks!
Sulfurik K. Nosferathus (Darth_Sulfur)
www.SulfurMidis.com
www.SulfurSoft.tk
http://www.BeepXtreme.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
|