|
You really don't want to be doing this - it's asking for trouble. You'd be much better using something like boost::shared_ptr in the vector rather than raw pointers - then, if required you can pass custom deleters into the function.
Below is an example of a template function which does what you requested. Depending on usage the call to clear() may be redundant, or may not do what you expected.
template<class T>
void cleaner(std::vector<T>& v)
{
typedef typename std::vector<T>::iterator iter;
iter cur(v.begin());
iter end(v.end());
for(; cur != end; ++cur)
{
delete (*cur);
}
v.clear();
}
EDIT: fixed typo
|
|
|
|
|
Thanks that worked great.
This is the part I couldn't figure out.
<br />
typedef typename std::vector<T>::iterator iter; <br />
iter cur(v.begin()); <br />
iter end(v.end());<br />
|
|
|
|
|
Perhpas I've mad a mistake here, but I'm writing an application, and the short question is the: My division seems to be incorrectly calculating:
....
double divisiontest = 5/9;
cout << setprecision (4) << divisiontest << endl
...
the result I'm getting is: 0.00000000000
as a minimum I should get .5556 ??????
|
|
|
|
|
try this :
double divisiontest = 5.0 / 9.0;
It was attempting to divide two integers and 0 would be the correct answer for that.
|
|
|
|
|
Thank for the simple solution, but just so I understanding this what's the difference between two syntaxs?
|
|
|
|
|
5 / 9 = .5556 in real life. The compiler interprets the 5 and the 9 as integers because nothing is telling it otherwise. So in your example, 5 / 9 = 0.5556 = 0 as an integer. I believe that the default data type is integer.
5.0 / 9.0 explicitly tells the compiler that the two numbers are a double data type so you would get the correct answer.
If you had written the first as:
double five = 5;
double nine = 9;
double answer = five / nine;
you would also get the correct answer since you had declared the variables as doubles to begin with.
|
|
|
|
|
According to the compiler, 5 and 9 are integers and divsion of an int by an int results in an int. If one (or both) of the numbers are of type double, then the result is a double. So
double divisiontest = 5.0 /9 ;
...
will give you the correct answer.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
This would also solve the problem
double divisiontest = (double)5/9;
m0n0
|
|
|
|
|
Hello fellows. I'm doing a class library in C++.NET, and I declared two classes, A and b, as follows:
<br />
public __gc class B; <br />
<br />
public __gc class A : public baseA <br />
{ <br />
private: <br />
B *entrada; <br />
B *salida; <br />
}; <br />
<br />
public __gc class B : public baseB <br />
{ <br />
private: <br />
A **entrantes; <br />
A **salientes; <br />
};<br />
However, while compiling I get the following error:
error C3160: 'entrantes' : cannot declare interior __gc pointer or reference as a member of 'espacio_nombres::B'
error C3160: 'salientes' : cannot declare interior __gc pointer or reference as a member of 'espacio_nombres::B'
Why this error happens? What can I do about it?
Thanks for your thoughts.
Regards,
KK.
One day you'll find
that I have gone,
for tomorrow may rain, so
I'll follow the sun...
|
|
|
|
|
|
I look it over on my MSDN copy, but I didn't fully understand. As far as I understood, this error means that a class cannot have a pointer to another managed class, which really sounds to me rather absurd. That's why I posted this message, because I think somehow I didn't understand that quite well... Any thoughts?
Regards,
KK.
One day you'll find
that I have gone,
for tomorrow may rain, so
I'll follow the sun...
|
|
|
|
|
Hi all,
I want to let the user to select any time zone they like from the list of time zones.
I made some research to get the list of time zones..
some say, get it from register..
Would you please tell me how to get all avaliable time zone?
Thank you.
|
|
|
|
|
These Api will help:-
EnumTimeFormats<br />
EnumDateFormats<br />
EnumCalendarInfo<br />
EnumUILanguages
and for more Info visit this link:-
National Language Support[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
I get the following error message when trying to cout a variable of type __int64 in VC++:
" error C2593: 'operator <<' is ambiguous "
Why is this? How can I print variables of type __int64?
Thanks a bunch guys
|
|
|
|
|
Actually, let me tell you what I am trying to do. I am taking a number C to the D power mod N.
C is a 7 digit number, and D is a 7 digit number. As an example, C squared is a 13 digit number. Thats why I need a data type that can hold very large numbers, and I figured __int64 is what I need.
What algorithm woul you use here?
Thanks a lot.
|
|
|
|
|
cout doesn't overload the << operator with __int64 (I think because __int64 is a MS VC++ feature, not part of the C++ standard).
You can use _i64toa() to print them. Or if you want it to work with cout the following seems to work fine:
std::ostream& operator<< (std::ostream& ostrm, __int64 i)
{
char szBuff[65];
_i64toa(i, szBuff, 10);
return ostrm << szBuff;
}
int main(int argc, char* argv[])
{
__int64 i = 9223372036854775807;
std::cout << "i = " << i << std::endl;
return 0;
}
|
|
|
|
|
That's the problem: When the program running on a Windows Server 2003 cluster creates a resource of "Generic Application" type, it needs two properties to be set: command prompt and directory path.
I've studied MSDN back and forth and it didn't help.
Can anyone help with an example, please?
|
|
|
|
|
Sederik wrote:
I've studied MSDN back and forth and it didn't help.
Did you see this:
WCHAR szCommandLineData[] = L"c:\\bin\\myapp.exe";
CLUSPROP_SZ_DECLARE( CommandLineValue, sizeof( szCommandLineData ) / sizeof( WCHAR ) );
CommandLineValue.Syntax.dw = CLUSPROP_SYNTAX_LIST_VALUE_SZ;
CommandLineValue.cbLength = sizeof( szCommandLineData );
lstrcpyW( CommandLineValue.sz, szCommandLineData );
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes, I did. Unfortunately, I didn't understand how it could be linked to a specified resource.
I'll try to clear it: I have a ~10 Generic Application resources created and each of them uses different command. For each of them I run the above code, but I don't know how the resulting value can be set as a property for a resource.
|
|
|
|
|
I understand that I might be in a wrong place to ask this question, but if you do have an answer, please help me out thank you
I am trying to use Borland C++ Builder 6 to parse an XML file, and I couldnt find a way to get child nodes..
if you could, please provide me an example or show me how to
THank you
Elapid For The Win
|
|
|
|
|
I assume there is some sort of DOM implimentation in Builder, which means that you load the XML into a document class which provides selectnode type methods. You select nodes using XPath, perhaps a google of builder xpath would give more concrete info ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How to access the variables declared in Doc.h from another .cpp?
(NOT accessed from View.cpp)
Thanks!
|
|
|
|
|
The proper way to do it would be to create a public method in the document's class that would provide access to the member variable. Something like:
class CMyDocument : public CDocument
{
public:
int GetSize( void ) const
{
return m_nSize;
}
private:
int m_nSize;
};
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
An oldie, but a goodie:
How To Get Current CDocument or CView from Anywhere
One you get the document pointer, you can access the data using the code similar to what David posted.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|