|
Ivan Cachicatari wrote:
You can use the CStringTokenizer class...
Which uses MFC.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
|
Hi i've got these two data structures:
obj *pObj1 = new obj[10000];
obj **pobj2 = new (*obj)[10000];
for (int i=0;i<10000;++i);
pobj2[i]=new obj;
which are the advantages and disadvantages from each one of them?
i know it's an exam question, but it seems to be interesting. i can't think of many.. first, i think the first one is easier to use, but the second one is more like ordered.
i'll really appreciate your help!!
thanks!
|
|
|
|
|
1. The first is much easier to understand for most people
2. The second is useful when you might have to use a 2D array.
3. The first method allocates memory for the objects in one big allocation. If there is not enough contiguous memory left it will fail. The second method is good when memory is fragmented as it allocates individual chunks of memory for each object.
4. The second is useful if two items in the array must actually point to the same object - in the first case, each array element is unique.
Those are a few to get started
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
1) static: you can't change the size of your array.
2) dynamic you can create and destroy your array using new and delete.
This comes in quite handy when you need a flexible array
example of the second for a 2 dimensional array:
temp = new CString*[nrofrows];<br />
for(int y = 0; y < nrofrows; y++){<br />
temp[y] = new CString[nrofcols];<br />
for(int z = 0; z < nrofcols; z++){<br />
temp[y][z] = "";<br />
}
}
AND (VERY VERY IMPORTANT!)
for(short x = 0; x < nrofrows; x++){<br />
delete []temp[x];<br />
}
delete []temp;<br />
temp = NULL;
hope this helps.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
2. if obj is large, or otherwise expensive to create, then if you wrap access to the array you can defer creation until first access.
2. allows array of obj* or any derived class objects, 1. only allows obj.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
The first consumes 10000 * sizeof(obj) bytes of the heap while the second consumes 10000 * sizeof(obj*) + 10000 * sizeof(obj) bytes of the heap. That could be a 40000-byte disadvantage. It all depends on the application, however.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
in a regular old console program using the main function
main( int argc, char argv[] )
how do you detect if there is a previous instance of the program?
|
|
|
|
|
If you are going to run on Windows, then the same way every one else does - you use some combination of Mutex or Event checking. See the articles on this website, they would still apply to a Windows console application.
|
|
|
|
|
ok, lately i have been writing function for strings
like SubString, StrFind, etc.
i want to make a StrReplace but i cant really come up with a good way to do it, so does anyone have an example such a function (StrReplace)
(note im not really using any classes in this)
|
|
|
|
|
You could try out memmove or memcpy but these functions need to be handled with care.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Well, last night sometime after i got off the net i had a revelation on how to do it, sat down and in 15 minutes i had it. it works quite good too, i owuld post it it but uses two other functions i made, and they other functions, so i would end up having to post my entire header file that im making.
|
|
|
|
|
(Sorry for the spam, but here's a proper version without the <> getting eaten.)
I'm trying to store boost::shared_ptrs in a std::map with a const std::string as the key.
The trouble arises when I need to find a value. Using find() yields an iterator, but VC2003 doesn't like it:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'boost::shared_ptr<T>'
with
[
_Ty=std::pair<const std::string,boost::shared_ptr<Sprite>>
]
and
[
T=Sprite
]
And here's the bit of code that causes this reaction:
map<const string, shared_ptr<Sprite> >::iterator frameSet = mysprite.find("animationName");
What I had hoped was that frameSet would be an iterator that I could dereference to call member functions on the Sprite object. But, alas.
Anyone have any suggestions?
tentons
|
|
|
|
|
I'm trying to store boost::shared_ptrs in a std::map with a const std::string as the key.
The trouble arises when I need to find a value. Using find() yields an iterator, but VC2003 doesn't like it:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'boost::shared_ptr<t>'
with
[
_Ty=std::pair<const std::string,boost::shared_ptr<sprite="">>
]
and
[
T=Sprite
]
And here's the bit of code that causes this reaction:
map<const string,="" shared_ptr<sprite=""> >::iterator frameSet = mysprite.find("animationName");
What I had hoped was that frameSet would be an iterator that I could dereference to call member functions on the Sprite object. But, alas.
Anyone have any suggestions?
tentons
|
|
|
|
|
OK, I've been playing with C++ (for windows apps) only for about a week now. What I'm trying to do is create a toolbar in my main (and only) window. Now I can do that, but I want to use a toolbar I've created in the Resource Editor in MSVC++ 6.0, and just can't seem to figure out how to implement it from there instead of creating it from scratch. I've tried google and MSDN, any help would be appreciated.
I'm not using MFC, so I've been calling CreateWindowEx(...) to create the toolbar.
Thanks =oP
Ian
|
|
|
|
|
Posting your problem twice will not get you any more answers or a quicker response. Be patient.
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Dear programmers,
I'm accessing an Excel object and trying to manipulate it.
I'm having trouble copying a worksheet in VC++ (MFC).
So far, some function that i've used was working fine except the copy function of Worksheet class. There's no error during compilation, but at runtime a message is displayed stating that "Copy method of worksheet class failed."
Please help me with this one ...
By the way, I am using MS Office 2000.
Thanks in advance.
|
|
|
|
|
I assume this is a debug message or an exception/run-time error message you're getting ?
In that case, you should check the actual worksheet. Is it locked ? Do you have priviledges to read/modify it ? Protected by a password ?
Last option is to use the debug mode to step through the code, and see if a function returns an errorneus value or receives an incorrect parameter.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I already set the worksheets property accordingly.
I also step through the code in debug mode, but I could not understand the return values of the function, it shift to a different source file.
Here's a sample of my code...
<br />
_Application appExcel;<br />
Workbooks books;<br />
_Workbook book;<br />
Worksheets sheets;<br />
_Worksheet sheet;<br />
Range range;<br />
<br />
<br />
if( !appExcel.CreateDispatch( "Excel.Application" ) )<br />
{<br />
AfxMessageBox( "Excel couldn't start." );
return ;<br />
}<br />
appExcel.SetVisible( FALSE );<br />
<br />
COleVariant UpdateLinks( ( long ) TRUE, VT_BOOL ), <br />
ReadOnly( ( long ) FALSE, VT_BOOL ),<br />
Format ( ( long ) TRUE, VT_BOOL ),<br />
Password( ( long ) FALSE, VT_BOOL ),<br />
WriteResPassword( ( long ) FALSE, VT_BOOL ),<br />
IgnoreReadOnlyRecommended( ( long ) FALSE, VT_BOOL ),<br />
Origin ( ( short ) 2 ),<br />
Delimiter( ( long ) FALSE, VT_BOOL ), <br />
Editable ( ( long ) FALSE, VT_BOOL ), <br />
Notify ( ( long ) FALSE, VT_BOOL ), <br />
Converter( ( long ) FALSE, VT_BOOL ), <br />
AddToMru ( ( long ) TRUE, VT_BOOL ); <br />
<br />
books = appExcel.GetWorkbooks( );<br />
book = books.Open( m_strReportPath, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, <br />
IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru );<br />
<br />
sheets = book.GetSheets( );<br />
sheet = sheets.GetItem( COleVariant( ( short ) 2 ) );<br />
<br />
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);<br />
sheet.Activate( );<br />
sheets.Copy( COleVariant( (short) 2), COleVariant( (short) 1));<br />
<br />
book.Save( ); <br />
books.Close( );<br />
appExcel.Quit( );<br />
|
|
|
|
|
Why does code like this sometimes result in a compiler error?
mpGlobalQueue->mPushQueue(::GEOSIT_IN, NULL, ::SHUTDOWN);
GEOSIT_IN and SHUTDOWN are perfectly valid constants that exist in the global name space. I can use :: to identify global functions within classes, which is very helpful when reading code. But many times when I try to identify constants as global, in this way the compiler gives me errors like the following:
error C2589: 'constant' : illegal token on right side of '::'
|
|
|
|
|
This is most often caused by a compiler misunderstanding the context. Another reason for it might be a syntax error earlier in the file. Although what you've written right there is correct, the compiler doesn't quite get it.
Try using a space between the opening parenthesis and the first constant. Another trick is to encapsulate the constant into parenthesis' of its own. This forces the compiler to first evaluate the constant value, and then supply it as a parameter to the function. In this case, the compiler (perhaps) thinks that GEOSIT_IN is a member of mpGlobalQueue , which I presume to be an object, struct or union. This causes the error.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks for the tip. That is what I thought as well, however even after supplying the parenthesis around the constants, the same error was reported by the compiler. The rest of the code compiles fine and only when I remove the usage of the global scope operator does visual studio compile completely.
|
|
|
|
|
you cannot use :: operator for constants defined using #define. It can be used only for declared identifiers. Look the following code
#define CONSTANT1 100<br />
<br />
const int CONSTANT2 = 100;<br />
<br />
main()<br />
{<br />
<br />
cout << ::CONSTANT1;
cout << " " << ::CONSTANT2;
}
|
|
|
|
|
Oh. That would be the problem. I did not know that. Thank you.
Shawn
|
|
|
|
|
How can I set a hook on a certain window fucntion like RegCreateKey for example because I want to design a firewall that looks over the registry.
To set the hook on a ceratin fucntion and my function should be called firts befeore that certain function is called
gabby
|
|
|
|