Forum: C++ Apr 9th, 2009 |
| Replies: 10 Views: 657 Siddhant, everybody knows some variable preceded by & is a reference. What I meant is the actual parameter represented by head is a pointer to a list of pointers. That is exact in the case of a... |
Forum: C++ Apr 9th, 2009 |
| Replies: 4 Views: 403 Other than that, in function assign , you are using local variables, which make it meaningless. |
Forum: C++ Apr 9th, 2009 |
| Replies: 10 Views: 657 head is a pointer to a list of pointers. If you pass head only (passing by value), the changes on head won't have any effect. That is why you are passing it reference. |
Forum: C++ Mar 24th, 2009 |
| Replies: 8 Views: 750 I just tried it in VC++ 8 and it works fine for me. his is the program I tried. |
Forum: C++ Mar 24th, 2009 |
| Replies: 1 Views: 466 I'm not sure if C++ permits that.
Better you can try
Animal* a1 = new Animal();
Animal* d1 = new Dog()
Then you can use dynamic_cast, if needed |
Forum: C++ Mar 24th, 2009 |
| Replies: 8 Views: 750 I think it is because of buffering of cout. A call cout.flush() may help. (I didn't try it. So pls excuse if it is wrong) |
Forum: C++ Mar 6th, 2009 |
| Replies: 6 Views: 3,901 I don't know if there is any stl hash_map. U need to use just map instead, with a #include <map> |
Forum: C++ Mar 5th, 2009 |
| Replies: 10 Views: 977 Do you have destructor for a function to clean up the locals inside? |
Forum: C++ Mar 5th, 2009 |
| Replies: 4 Views: 301 OK.. I understood.
However, I think your sequence would enter the for loop only if both list1->getNxt() == NULL and list2->getNxt() == NULL because of the terminationg condition in for loop. Are you... |
Forum: C++ Mar 5th, 2009 |
| Replies: 7 Views: 641 A general way is to flush the input stream (instead of using getchar()).
Use |
Forum: C++ Mar 5th, 2009 |
| Replies: 6 Views: 3,901 The map as a whole can not displayed using cout. Try |
Forum: C++ Mar 5th, 2009 |
| Replies: 4 Views: 301 Is the value of result != NULL when you invoke the function? I don't see you do a new operation on result anywhere in the function.
As you stated, if it is really non-null, the program would crash... |
Forum: C++ Mar 5th, 2009 |
| Replies: 6 Views: 684 Of course, if you put the delete statement after the return statement, it won't be executed at all. Instead you can do like |
Forum: C++ Mar 5th, 2009 |
| Replies: 6 Views: 684 If you are afraid of delete, using auto_ptr can be a good option. |
Forum: C++ Mar 5th, 2009 |
| Replies: 10 Views: 977 However, having multiple exit points for a function makes it difficult to maintain. There is a greater chance that you'll forget to do the clean ups (which will be usually at the end of the function). |
Forum: C++ Mar 5th, 2009 |
| Replies: 2 Views: 456 Why are you trying to read a double using "%d"? Use "%lf" instead. |
Forum: C++ Mar 4th, 2009 |
| Replies: 5 Views: 262 Yes you are right. My apologies...
Thanks for correcting me. |
Forum: C++ Mar 4th, 2009 |
| Replies: 8 Views: 278 Try this.
http://cppkid.wordpress.com/2009/02/18/how-to-round-off-a-number/ |
Forum: C++ Mar 4th, 2009 |
| Replies: 5 Views: 262 You don't have to go upto sqrt(num). The loop may be like this. |
Forum: C++ Feb 27th, 2009 |
| Replies: 3 Views: 594 To sort an array, see the following article. It is simpler than you writing your own algorithm.
http://cppkid.wordpress.com/?s=how+to+sort+an+array |
Forum: C++ Feb 19th, 2009 |
| Replies: 7 Views: 1,132 The problem is that when your function is returning a string, it first makes a copy of the string to be returned (in your case, it is NULL). For making copy, it has to take the length of the original... |
Forum: C++ Feb 18th, 2009 |
| Replies: 6 Views: 764 This may be helpful to round off a number.
http://cppkid.wordpress.com/2009/02/18/how-to-round-off-a-number/ |
Forum: C++ Feb 18th, 2009 |
| Replies: 4 Views: 297 The problem seems to be in
while(isalpha(ch))
{
text[i] = ch;
i++;
}
If the first character is an alphabet, it will go on filling the array text with that... |
Forum: C++ Feb 18th, 2009 |
| Replies: 2 Views: 567 The question is not much clear to me. I assume that you have a class with a public member, say
class CMyClass
{
public:
int iNo;
};
Then you can access iNo as |
Forum: C++ Feb 11th, 2009 |
| Replies: 2 Views: 397 Exactly........
Have a better practice to initialize Point at the time of declaration. |
Forum: C++ Feb 11th, 2009 |
| Replies: 3 Views: 290 I'm not sure what type of a vector stuAns is.
If it is a vector of char*, you have to use strcmp() instead of checking with the operator !=. |
Forum: C++ Feb 9th, 2009 |
| Replies: 7 Views: 974 I think you can simply check if the first character is a numeral. |
Forum: C++ Feb 9th, 2009 |
| Replies: 3 Views: 810 isn't it possible to use a map rather than using two separate vectors? Then, I think, the entire problem will be solved. |
Forum: C++ Feb 9th, 2009 |
| Replies: 4 Views: 1,002 Please refer to this link. It may be helpful.
http://www.codeproject.com/KB/database/cspreadsheet.aspx |
Forum: C++ Feb 9th, 2009 |
| Replies: 2 Views: 1,137 Sorting the stack is easy. I have written in my blog how to sort an array in simple steps.
http://cppkid.wordpress.com/2008/09/18/how-to-sort-an-array/
Hope this will clear your problem. |
Forum: C++ Feb 9th, 2009 |
| Replies: 3 Views: 534 The operators like . , -> and * can not be overloaded. |
Forum: C++ Feb 9th, 2009 |
| Replies: 4 Views: 622 only the first example invokes copy constructor. If the second one needs to work in the same manner as copy constructor does, you have to overload the assignment operator. |
Forum: C++ Feb 9th, 2009 |
| Replies: 7 Views: 2,388 Of course this will work. However, what is the need of a separate class just to implement the < operator. Does it have any more advantage than implementing in the struct itself? |
Forum: C++ Feb 3rd, 2009 |
| Replies: 7 Views: 2,388 To use find function, you have to implement operator < in the key struct. Then it will be ok.
Once I had a similar problem in sorting a vector and I have written it in my blog.... |
Forum: C++ Feb 3rd, 2009 |
| Replies: 5 Views: 554 Which compiler are you using? I'm using Visual Studio 2005 and the code compiles perfectly. Also, it creates an array of pointers to objects. |
Forum: C++ Feb 3rd, 2009 |
| Replies: 5 Views: 554 Instead of the line
Foo* f = new Foo[2]("Hello");
you have to use
Foo* f[] = {new Foo("Hello"), new Foo("Hello"));
Then for deleting, you have to iterate throgh each element of the array. |
Forum: C++ Jan 23rd, 2009 |
| Replies: 3 Views: 332 p is the object itself (just another name for *obj, not obj). References are internally treated as pointers. However, it is hidden from the programmer. |
Forum: C++ Jan 15th, 2009 |
| Replies: 8 Views: 1,049 How the value of PI can be printed as a table? |
Forum: C++ Jan 15th, 2009 |
| Replies: 8 Views: 535 [] operator is the best to add values to an array, I think. Applicable only if you know the index in advance.
If you have to search in runtime for the position to which we can add a value, it will... |