|
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
|
|
|
|
|
http://www.codeproject.com/system/hooksys.asp
http://www.codeproject.com/dll/apihijack.asp
There you go
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I want to learn more on c++ & java scripting and how all this plays out in the MMROPG industry. As I have been reading more and more daily on this i feel that I am progressing and as I read a book from John Smiley (Learn C++) I'm not sure if that is the actual title but hey when I'm stuck in the Seattle Traffic, I can pop a few pages into my memory bank.
I would like to know if someone can lead me in the right direction as to what, where or who I need to talk too, also as my research has compiled I have found I am in need of SoftICE, WDASM, x86 ASM and DHack, Note Pad, WPE Pro, to do what they call packet handling on these servers, as I have know clue what or where to start on all that. I ask for some experienced guidance in this aspect and explaination of what SoftIce, WDASM, x86 ASM and WPE Pro is and if there is a simplier method please feel free to leave something here in the forum and I will check back daily.
Thanks
Jimmy
|
|
|
|
|
mztrjimmy wrote:
I would like to know if someone can lead me in the right direction as to what, where or who I need to talk too
Start slowly.
SoftICE and the other tools are fairly 'Hard Core' types of things that you don't want to mess around with unless you have to because of the steep learning curve. My suggestion is that Microsoft Visual Studio is the easiest way to get started in most languages - especially compared to notepad.
Scripting
Scripting is a great way to get started with modding games, neverwinter nights and unreal tournament both have scripting system that have been used extensively.
Learn the syntax of one major language.
C++ is a great place to start, but C# and java are IMO slightly easier to get started with, if you get really serious then you'll probably come back to c++ eventually anyway.
Learn the basics of win32 programming.
The easiest way to get started is MFC, when you feel comfortable with MFC try the raw win32 API. Also, don't neglect the operating system fundamentals like sockets and threads - apart from being useful in general they form the backbone of almost all server applications.
Who to talk to?
Game Programming
http://www.flipcode.com[^]
http://www.gamedev.net[^]
Windows / MFC
Here of course!
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|