- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 4
- Posts with Upvotes
- 3
- Upvoting Members
- 4
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
16 Posted Topics
Re: Why would you want to simulate a stack for a vector if there is already an implemented stack?! [CODE]#include <stack> #include <iostream> int main() { std::stack<int> st; st.push(1); st.push(3); std::cout << st.top() << std::endl; // outputs 3; st.pop(); std::cout << st.top() << std::endl; //outputs1 }[/CODE] | |
Re: Die::Die() //Initializes Face data member { Face = 1,2,3,4,5,6; } I am not sure what you wanted to achieve by this, but this assigns 6 to Face. The operator comma works like this - it evaluates all of its arguments from left to right then returns the rightmost argument, in … | |
Re: Fbody's solution is a bit bad because it changes the semantics of the built-in operator-. Consider it. [CODE]struct example { int anInt; }; //Overload the Unary minus for the "example" struct: void operator- (example &o1) { o1.anInt = -o1.anInt; } #include <iostream> void Print(example e) { std::cout << e.anInt; } … | |
Re: You have never allocated memory for AgentP member. This should fix the problem [CODE]Agent::Agent(std::string name) :AgentP(new AgentStruct()) { AgentP->nextAgent=NULL; AgentP->agentName=name; AgentP->pID=setPID(); AgentP->mID=AgentP->pID; } [/CODE] | |
Re: ::name is explicitly specifying that name is in global namespace example 1: [CODE]int i = 3; int main() { int i = 4; if(true) { int i = 5; int j = ::i; //j is set to 3 } } [/CODE] example 2: [CODE]int main() { int i = 4; … | |
Re: I know I'm a bit offtop here, but I would like to say that not only the default access of members is the difference between a class and a struct,but also the access of derivation is public for structs by default and private for classes. Also the word class can … | |
Re: [CODE]#include <algorithm> void reverse(char* str) { std::reverse(str, str+strlen(str)); }[/CODE] | |
Re: You mean 1 decimal place after the point? Like 13.4 or 2333.4. I'll go with yes. If you want to obtain the value with 1 decimal place after the point, then you should do this double x = some value; double y = x = int(x*10)/10.0; this will however not … | |
Re: pointer to array of character strings... If by character string you mean const char*, and if you MEAN you want to declare a pointer to array of pointers to const char(which I doubt), then it will be like this [CODE]typedef const char * str_type; typedef str_type arr_type[100]; typedef arr_type* my_desired_type; … | |
Re: first of all, instead of [CODE] while(1){}[/CODE] write [CODE] cin.get(); [/CODE] :) Second, can't see a destructor that deletes all the memory you've new'd. Third, getStudent can be much shorter, like this [CODE] void getStudent (string student) { node* current = start; while(current!=NULL) { if(current->name == student) { cout << … | |
Re: in the end of main, write cin.get() which will wait for you to press enter so it won't close | |
Re: float a; cin >> a; a = a*a; well, this is the fastest way I am aware of, perhaps you could make it a tiiiiiiiiiiny bit faster with a *= a; but probably most compilers will optimise this anyway. Bit shifting is about integers, and you can't use it (I … | |
Re: I believe the specialization alternative (although technically speaking function templates cannot be specialized, this is rather an overloading) is indubitably superior to the Runtime Type Identification. | |
Re: I am not sure if I understand your question correctly. Do you mean you want to read a file into an array of words? or lines? Anyway, why use arrays instead of vector? I would do it like this [code] #include <fstream> #include <string> #include <vector> int main() { std::vector<std::string> … | |
Re: [QUOTE=daviddoria;1325204]You need to put single quotes around the letters You should also [icode]return 0;[/icode] at the end of main(). You should also have an [icode]else[/icode] statement to help catch things like this :) Hope that helps, David[/QUOTE] You absolutely should not. The current C++ standard requires that the return type … | |
Re: assert(expr); if expr evaluates to true, then OK else if in debug mode - calls abort else - does nothing but this is probably bad one can use BOOST_VERIFY which is basically like assert, but works in release mode too |
The End.