|
<br />
class classA <br />
{<br />
public:<br />
addObject(Object newObject); <br />
<br />
private:<br />
list<Object> objectList;<br />
};<br />
<br />
class classB <br />
{<br />
private:<br />
classA* Aptr;<br />
void addObjectToClassA();<br />
};<br />
void ClassB::addObjectToClassA() <br />
{<br />
Object newObject();<br />
Aptr->addObject(newObject);<br />
}
Hello all,
I have what is probably a simple question, but I've been wrestling with it for a while. I have code that looks like what I typed above. classA has an std::list of Objects. classB has a method that will add a new Object to that list in classA. As I understand it, it creates a copy of the Object and the copy is what is added to the list.
How can I iterate over objectList and actually modify the objects in the list? When I iterate now it seems that the Objects in the list are not modified... It seems that copies are modified instead. I thought one option would be to make objectList a list of pointers to Objects instead... But what will happn when I add an object to the list in classB? If I create a local Object* and add that to the objectList, does the pointer get added or does a copy of the pointer get added? (I'm just worried that the pointer won't refer to anything after addObjectToClassA() exits).
Thanks!
-Jordan Atlas
|
|
|
|
|
I don't believe that a copy is made when you add something to a list, but either way, if a pointer is copied, it still points to the same memory address.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
but either way, if a pointer is copied, it still points to the same memory address.
Yes, but if I have a function like this:
<br />
void ClassB::addObjectToClassA() <br />
{<br />
Object* newObject;<br />
Aptr->addObject(newObject);<br />
}<br />
What happens after the function exits? Does the pointer point to anything (sensible) anymore?
Thanks,
-Jordan Atlas
|
|
|
|
|
No, it never pointed to anything sensible.
Object * newObject = new Object();
NOW you have a pointer to something sensible, and you can make as many copies of that pointer as you like. Until you put
delete newObject;
it will continue to exist, and if you fail to ever call delete, you've got a memory leak.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
If a STL list contains objects instead of pointers to objects, then objects added to the list get copied, just like with all other STL containers.
|
|
|
|
|
Yeah, I realised after commenting that I'm too used to C# now. It's still the case that if you have an iterator, you can modify the object, and the object in the container will be modified, because you have a reference to the object in the container, right ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hello,
I am working on a VS.net SDI project, and keep all the project files in version control. What is the project.ncb file? Does it need to be included in version control?
I am sure it does not need to be included, but was just wondering before I remove from the set on controlled files that I have.
Thanks.
Jerry
|
|
|
|
|
no need to put it in version control, the ncb will be recreated by the IDE.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I am trying to call a matlab function (namely convhulln) in my C++ code. I do not know which matlab/library/dll files to include. I realize that it is a slightly complicated process to get everything right. Does anyone know of any links to working step-by-step tutorials. I have tried matlab's and a few others and haven't gotten them to work. Thanks in advance.
Tony
|
|
|
|
|
|
Hi,
1. I m learning the vc++ , some of my friends told me Microsoft will plan to quit vc++ ,bcz of . NET , is true ?
2. Is possible 2 work vc++ in .NET frame work . How ?
3. can we call vc++.net is the .net implementation of vc++ ( bcz vb -> vb.net ) ?
4. Can anyone tell me about the future of vc++ after the boom of .NET .
with lot of doubts
babuji
|
|
|
|
|
Here is one person's opinion on the subject. For every other person that you ask, you will get as many opinions.
babuji mohandas wrote:
2. Is possible 2 work vc++ in .NET frame work . How ?
Yes. Perhaps this book would be of use to you.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
Can anyone tell me how safe/unsafe it is to use dlls built in VC7.1 in the application which is built with VC6.
The dll built with VC 7.1 requires system dlls like mfc71*.dll, msvcp71*.dll, msvcr71.dll, etc. If I copy these dlls either in local foler or in system 32, the application loads fine, but Is it safe?
Please post your detailed comments. Also, if you know any URL for technical information do let me know.
Thanking you in advance.
Best regards
Vicky
|
|
|
|
|
If it's a normal win32 DLL, and the entrypoints don't take MFC classes as parameters, you should be fine, even if the DLL and the program using it use different versions of MFC internally. Passing MFC classes between modules built using different versions is just asking for trouble though.
Oh, and don't free in one module memory allocated in the other.
Shog9
I'm not the Jack of Diamonds... I'm not the six of spades.
I don't know what you thought; I'm not your astronaut...
|
|
|
|
|
I have a 3rd party program that writes data to a selected file.
Instead of having the program write to a file, I'd like to be able to create a virtual file and capture the data the program writes.
I've tried doing it with named pipes, but I can't get it to work*.
Are there any other ways to create a virtual file?
Thanks
* Even though a simple CreateFile,WriteFile,CloseFile program works, the copy command returns "All pipe instances are busy." error and GUI programs just hang for a few seconds after I press save.
|
|
|
|
|
Forjer wrote:
I'd like to be able to create a virtual file and capture the data the program writes.
Do you mean intercept "write" calls to a certain file? If so, check out this utility.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I'm familiar with Filemon, but it doesn't help me get the data and skip the disk writing.
|
|
|
|
|
I was simply providing the link to give you an idea as to what is involved in intercepting file I/O. Suffice it to say, it's not a trivial undertaking.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I thought I could avoid api hooking because I can control the output file name.
I'm currently looking into madCollection as it appears I have to use api hooking.
|
|
|
|
|
Hi ,
WHat about memory mapped files ??? Iam not sure what you are looking for ....but looks like memory mapped file might help you ...
Cause is my effort;
Effect is God's effort
|
|
|
|
|
That's not going to help in my case.
|
|
|
|
|
SetThreadLocale does not seem to work... or does not do what I want it to do : on a computer with regional settings set to French (meaning the decimal point will be a comma), the following code
_tsetlocale(LC_ALL, _T(""));
BOOL bResult = ::SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT),SORT_DEFAULT));
CString strResult;
strResult.Format(_T("%.15g"),0.444);
::SetThreadLocale(LOCALE_USER_DEFAULT);
will write 0,444 in strResult and not the expected 0.444. I do not want to use _tsetlocale because all threads would be affected... and I do not want to have to synchronise them!
It seems like SetThreadLocale only allows you to change which resource you will access.
Any idea? Anything? Thanks in advance!
|
|
|
|
|
I'm thinking of writing a small utitlity app (or service) for my company to hook a certain url, and notify or stop the user from going there. For instance, if the user opens any browser (firefox, ie, etc) they should be able to go anywhere they want. But I would like to be able to detect if they go to www.notthissite.com/badpage.htm, and block it out or stop it. The reason for this is that we have an application that has a browser control that takes them to a specific url for data entry purposes. We also keep track of this input data in a database also, so we don't want them to put the data in through ie or firefox or whatever. I've come up with a few theories, but I don't know if any of them make any sense, so I'm just looking for any kind of input. Thanks in advance!!
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Blacklisting URLs is best done at the firewall or gateway. That's one of the features they provide. Is there a reason why you can't go this route?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
well, our app needs to have access to it. Also, they should be able to go to www.that.com or www.that.com/products.htm, but not www.that.com/dataentry.htm. However, our app should be the ONLY one to be able to access this particular specific page. Our network admin knows about firewalls (which is why I can only get to a few select sites ), but the guy who worked on the app that hosts the web browser control said that he spoke to him and I guess they didn't come up with a solution. Plus, I don't know exactly what rights we'll be granted to their network, so I was thinking that having an app/service running that's part of our install would be the best solution. I don't know much about networking or firewalls myself, but would it be possible to only allow one .exe to access a certain url through the firewall settings?
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|