|
One way would be to implement a equality operation (operator=) inside the class, then after you've created the array of new objects, you use the returned pointer to explicitly call the constructor you desire.
For example, consider this:
AA* aa = NULL;<br />
aa = new AA[3];<br />
<br />
aa[0] = AA::AA(5);
This would create a new temporary AA object, initialize it with number 5, then copy it's contents to replace the array's first object. Finally, it destroys the temporary object. If you don't want to write an equality operator, you can always use memory-wise copying.
The last way is to write a new operator New[] for your class. This means that you must explicitly call malloc to reserve memory for your new object. Writing this operator is a tedious work and must be done very carefully to avoid memory leak problems. To use an array declaration, you could possibly implement a variable-length argument list for the operator New[] , then get arguments from this list to initialize your objects with...
That requires, however, HARD WORK. The easiest thing to do would just use a member function to initialize the objects.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks Antti. The operator overloading thing does work.
I don't know how it didnot striked me at the first place.
regards,
Amol
|
|
|
|
|
Hi there
I have declared several Object ID's in the string table, then want to use these with Update_Command in the class wizard.
However they dont appear in the Object ID drop down box when I open the class wizard.
Any ideas
Thanks
Stu
|
|
|
|
|
Hi All,
How do I disable the context menu and keyboard inputs such as Cntl+O, Cntl+N,
and in the Internet Explorer Browser.
I have gone following through the articles of web browser customization in CP
http://www.codeproject.com/atl/MouseGestures.asp and
http://www.codeproject.com/internet/CustomBrowser.asp
The second article primarly host the webcontrol in the dialog box
application. Can these functionality be extended to the actual IE browsers.
I am running out of time... please help me
Thanks in advance,
Abhi Lahare
|
|
|
|
|
Hi,
How can I run a vbscript file from a VC program?
EXamples would be fine.
THanks in advance
regards
Hari Krishnan
|
|
|
|
|
Have a look around here for articles on the Windows Script Host (WSH). It's not something that can be answered in a message post.
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"
|
|
|
|
|
Hey all.
I noticed the VS_VERSION_INFO resource that is inside my program that I am building.
I am building code that displays the current version in various places. I would like to be able to pull the values from this VS_VERSION_INFO resource, instead of having to declare a version-info variable in my class -- which just makes more places for me to update it.
I checked MSDN about this and all that I can come up with is GetFileVersionInfo() method. I do not want to have to use a method if I don't have to that acutally looks at its own .EXE to determine the current version.
I am wondering if there is another method or some other way to grab those values from the resource at compile time?
Thanks!
|
|
|
|
|
Hi,
Search google for a class 'CModuleVersion' which can be used as
TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL,szPath,MAX_PATH);
CModuleVersion ver;
if(ver.GetFileVersionInfo( szPath , TRUE)){
CString s;
s.Format(IDS_STRING61504,HIWORD(ver.dwFileVersionMS), LOWORD(ver.dwFileVersionMS), HIWORD(ver.dwFileVersionLS));
SetDlgItemText(IDC_VERSION , s );//UnicodeConversion
}
Hari Krishnan
|
|
|
|
|
Does anyone know off hand why I cannot add an additional
control to my control heavy dialog using the Dialog editor in VC++?
If I remove an existing control, I can then
add. I'm hitting a limit somewhere perhaps?
(Its a busy dialog... )
Thanks for your help.
|
|
|
|
|
It took a while but here you go!
0x00050000 - 0x0005FFFF
from the MSDN article "TN028: Context-Sensitive Help Support".
That,s 65,535 possible IDs.
You should not be hitting a limit. Unless you are running out of memory or the resource editor has an unrealistic limit. I have placed large numbers of controls on dialog boxes before without any problems.
As an experiment, may be you could try creating and placing controls on a dialog programaticaly and see when it fails.
Good luck!
INTP
|
|
|
|
|
Sounds to me like your main problem is design skills.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
As harsh as the statement might sound, I would have to agree.
It really sounds like the time for a UI redesign.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Christian Graus wrote:
Sounds to me like your main problem is design skills.
Get a life. There are words for geeks like you, but I will spare
this fine forum. You have no idea what the requirements/design problems are. Nor do you know whether or not I'm the designer!
So you are completely out of line to suggest that I lack design skills.
The fact is, the software does need UI rework, but I've seen many a fine
application with more than 256 controls on a single dialog.
|
|
|
|
|
burnafatty wrote:
There are words for geeks like you,
Professional is one that springs to mind.
burnafatty wrote:
You have no idea what the requirements/design problems are.
Sorry for guessing that 'usable' was among them.
burnafatty wrote:
Nor do you know whether or not I'm the designer!
I didn't say you were, you moron. Whoever the designer is should be taken out the back and shot, and replaced with a monkey in a suit.
burnafatty wrote:
but I've seen many a fine
application with more than 256 controls on a single dialog.
Bollocks. You, sir, are an idiot.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
VC++ (v6, anyway) only allows 256 (I think...) controls to be placed using the dialog editor. The rest you'll have to manually put in the .rc file and not use the dialog editor, or create them dynamically.
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"
|
|
|
|
|
Thank you Ryan and John for some useful
input!
It does indeed seem to be the case that the VC++ allows one to only add
256 controls via the dialog editor.
A shame. Somewhat of an arbitrary limit, no?
Of course, I can simply add them by hand as Ryan suggests.
And speaking of design weaknesses... wouldn't surprise me if Christian
was the geek who decided a byte was enough to store the control count in
the VC++ Dialog Editor and that there is no need to inform the user when
the limit is reached !
Excellent help from the forum, despite the flames... Thanks again.
|
|
|
|
|
I have a class structure forming a linked list where there is another class (declared as private within the main class) such as
class Link
{
private:
class LinkElement {
friend class Link...
...
Is it possible to access the PRIVATE members of the LinkElement class from a function that is not part of either of the two classes? I am trying to go through the linked list in a thread and trying to set various pointers to both the class Link and LinkElement but can't get access to that member. Is this possible or am I wasting my time?
|
|
|
|
|
#define private public
Or cast (LinkElement *)(classpointer + whatoffestis)
Or make the accessing class a friend or make som
accessor functions.
/M
- Don't sweat the petty things, and don't pet the sweaty things.
|
|
|
|
|
Thanks for the speedy reply, but I'm a bit confused with your answer. Here is what compiles and what doesn't for me
cLink::cLinkElement *pPointer; (compiles with the class warning that it's not initialized to anything)
now doing this: pPointer->pNextLink = NULL; (it shows up fine on class view btw but I get this compilation error: error C2248: 'pNextLink' : cannot access private member declared in class 'cLink::cLinkElement'
Is there anyway to get around this by not making the privates publics?
|
|
|
|
|
You do get what private means, right? It's an implementation detail that you shouldn't rely on, because somebody is guaranteed to change it the moment you start monkeying about with it.
Ignore the suggestion of #define private public (although made in jest), because that's the sort of thing that shots you in the foot later on.
You can fudge a solution by declaring an identical class/struct (with the same compiler packing options, etc!), but without the use of private. If you're lucky, the compiler will generate matching object layouts, and you can reinterpret_cast a pointer from one type to the other, and then access the private members through that.
Use of this technique is extremely brittle, and if I was your boss or peer, I'd be distinctly unimpressed with you, and make you junk that code.
Generally speaking, what you're trying to do indicates you don't understand the problem correctly, you don't understand the language properly, or you have a crap design that needs rethinking.
And if this is homework, then go back to the textbooks
Ian Darling
"The different versions of the UN*X brand operating system are numbered in a logical sequence: 5, 6, 7, 2, 2.9, 3, 4.0, III, 4.1, V, 4.2, V.2, and 4.3" - Alan Filipski
|
|
|
|
|
You are right on the issue that I have crap design, but this is no means homework. I have been programming c++ for about 2 years, completely self taught, and learning by my mistakes as I go along, since I have no one to teach me and I am not doing this for a living.
I have found a workaround to this by not declaring that member private anymore.
My understanding of private is that it's a member of a class that can be accessed only by the functions of that class and/or the class object, correct?
Also, although your criticism is appreciated, and I know I am a really bad coder (should have seen me 2 years ago!!!!) a little help would be appreciated to go along with the criticism.
|
|
|
|
|
georgiek50 wrote:
a little help would be appreciated to go along with the criticism.
Point taken
What exactly are you trying to achieve? I might be able to provide more constructive guidance with a brief outline of the task you're trying to solve.
Ian Darling
"The different versions of the UN*X brand operating system are numbered in a logical sequence: 5, 6, 7, 2, 2.9, 3, 4.0, III, 4.1, V, 4.2, V.2, and 4.3" - Alan Filipski
|
|
|
|
|
I have read some of the replies and the best way to learn is by doing.
If you wish to access a private memvebers of a class from a function that is not part of the class, you need to do one of three things: Provide member functions in your class to access the private member variables (preferded method), declare your function(s) as a friend of the class (this says the function knows what it is doing), or make the member data public (this is normaly a bad idea).
I recommend the books by Bruce Eckel for learning more about the C++ language itself, although they concern the langauge and not any specific OS.
Good luck, and have fun!
P.S. I love programming!
INTP
|
|
|
|
|
Thanks to everyone for their replies. Although I don't think that books can help me out any more because I am stubborn and never learn until I make the mistake. John's comment about creating another member function to get the details from the private members sounds the best way (don't know why I didn't think of it myself...been at it for 10 hours today, probably that's why!)
Thanks, again.
|
|
|
|
|
I would like to know if it is possible to have BOTH VC++ 7.1 and VC++ 6 installed on the same computer without anything going haywire?
|
|
|
|