|
I doubt the name is the problem, it's more a potential problem. The constructor is a safer bet, the new one looks much better.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
i'll definitely rename it and change my destructor.
|
|
|
|
|
1. Where is the error occurring -- what line?
2. Did you notice that in your second constructor you don't initialize your "rows" member?
3. I recommend that you declare and initialize A in the same line: vector* A = new vector(15) ;. It's less code and it's safer.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
It's occuring the constructor. That is, in the line:
vec = new double[15] ;
|
|
|
|
|
do i need to intialize it in the second constructor when i have it as a member variable in the class?
|
|
|
|
|
so my class should be something like this
class vector
{
private:
int rows ;
double *vec ;
public:
vector(void) { rows=0 ; vec=0; } // default constructor
vector(int n) // constructor
{
rows=n ;
vec = new double[rows] ;
}
~vector(void) {delete vec} ; // destructor
} ;
|
|
|
|
|
is this how you would initialize it:
vector(int n) ;
{
rows=n ;
vec = new double[rows] ;
}
|
|
|
|
|
Other than not setting rows in you second constructor and not deleting vec in your destructor, there is nothing wrong with your code.
I created a simple console app and cut and pasted your code...no errors.
#include "stdafx.h"<br />
<br />
class vector<br />
{ <br />
<br />
private:<br />
int rows ; <br />
double *vec ; <br />
<br />
public: <br />
vector(void) { rows=0 ; vec=0; }
<br />
vector(int rows)
{ <br />
vec = new double[rows] ;<br />
}<br />
<br />
~vector(void) {} ;
<br />
} ;<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
vector* A ; <br />
A = new vector(15) ;<br />
<br />
return 0;<br />
}
just a memory leak
There has to be something else...Is this your entire code?
I think this is a good learning exercise...I would advise you to persue it and not spin your wheels over in STL land;)
Gary Kirkham
A working Program is one that has only unobserved bugs
|
|
|
|
|
Hi --
I have a simple question about dynamic memory and vectors:
Consider the vector class:
class vector
{
private:
rows ;
double *vec ;
public:
vector(void) { rows=0 ; vec=0; } // default constructor
vector(int rows) // constructor
{
vec = new double[rows] ;
}
~vector(void) {} ; // destructor
} ;
when i use the class in MAIN() like:
vector* A ;
A = new vector(15) ;
I get an error. It's giving a "null reference error" and saying that the object has not been instantiated..
I don't get what I'm doing wrong?
Thanks
KBL
|
|
|
|
|
how can one Move to a specific row on a database and not the position like if i want to Move to the data with the primarykey 10 and not the possition 10?i used:
nRow=m_pSet->primarykey;//where primarykey is =10
m_pSet->Move(nRow,SQL_FETCH_BOOKMARK)
but this does not work and SQL_FETCH_ABSOLUTE DOSENT EITHER
would apprecite any suggetions cos am stucked up here
|
|
|
|
|
Hello
I'm not shore on what you want to to but first you hav to make sure on that you can use the bookmark. with function CanBookmark(). To make the bookmark function avalible you must set the CRecordset::useBookmarks option in the dwOptions parameter of the Open member function.
If you are about to update certain fields in the database it is sometimes just as good to launch SQL to the CDatabase object with db.ExecuteSQL(SQL)
Cheers
Henrik
|
|
|
|
|
Hi
i am begginer in Visual C++ and i have a quiestion.
assume that we have an Window. in this Window we have some objects . for example we have 3 ICON in the window. how can i simply Drag one ICON(object) and move it everywhere i want and Drop it.
i don't want to use CImageList because using this Class we can't Drag 2 object altogher and we can Drag 1 image on each Drag-n-Drop operation.
if u want to underStand what i want to do See this Amazing applet :
http://www.seanet.com/users/arsen/avltree.html
in this AMAZING AVL Tree(that uses in DataStructure) u can Simply Drag a Node every where u want and Drop it. u can see that When u Drag a Node all of the Nodes are move altogether.
how can i do that ? Plzzz helpp meeee
Regards
|
|
|
|
|
Hi.
-=Ehsan-de-Burge=- wrote:
i am begginer in Visual C++ and i have a quiestion
How much of a beginner ? Are you experienced with C++ ? If not, you need to forget all this and learn C++ before you worry about this sort of stuff.
-=Ehsan-de-Burge=- wrote:
move it everywhere i want and Drop it.
You need to impiment a window ( to hold the icon ) that knows when it is clicked on and moves itself. Moving is easy, MoveWindow or SetWindowPos will do that.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
i learned C++ for 2 years. and i know Object Oriented Programming.
So u mean that i have to impiment a window for each Icon and place icon in it ?? and move this windows in the main Window ?
Sorry it seems that my knowlege is poor in Visual. but i am Guidable.
thanks anyway
|
|
|
|
|
-=Ehsan-de-Burge=- wrote:
i learned C++ for 2 years. and i know Object Oriented Programming.
That's cool then.
-=Ehsan-de-Burge=- wrote:
So u mean that i have to impiment a window for each Icon and place icon in it ??
I'd derive a class from CBitmapButton, it does the image stuff you want already. Then just capture mouse clicks and movement and when the mouse is down, call MoveWindow to move the button by the amount the mouse has moved when it moves.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
_beginthreadex / GetCurrentThreadId / GetCurrentThread
each return handles -- I have a thread object which holds the value returned from _beginthreadex().
Can I use that handle to compare with GetCurrentThreadId()? Will it be the same?
I want to put a method on my thread object that will have special behavior (an assert) when it is called from it's own thread....
The MSDN documentation for GetCurrentThread() and GetCurrentThreadId() are really not that helpful. It sounds like GetCurrentThreadId() is the actual handle, where GetCurrentThread() is not.
Any help out there?
Thanks in advance!
|
|
|
|
|
The documentation for GetCurrentThread and GetCurrentThreadId are very clear. GetCurrentThread returns the thread handle and GetCurrentThreadId return the thread ID. The problem is with _beginthreadex which has a confusing return type. It returns a handle even though it doesn't use the WINAPI HANDLE type.
So, test the _beginthreadex return against GetCurrentThread and you should be set.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
GetCurrentThread():
Return Values
The return value is a pseudo handle for the current thread.
Remarks
A pseudo handle is a special constant that is interpreted as the current thread handle. The calling thread can use this handle to specify itself whenever a thread handle is required.
--------
A pseudo handle? What's that? When they call it something like that, it makes me thing that it's not what it seems.... It would be clearer if it said, it returns "the handle".
It sounds like I have to test it to find out. It's also not clear if a thread calls GetCurrentThread() if it will always return the same value.
|
|
|
|
|
Is there a way to check if 2 handles refer to the same object?
|
|
|
|
|
Peter Weyzen wrote:
A pseudo handle? What's that?
Read the entire remarks section, which explains it quite succinctly. The key being the last paragraph:
"The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with this handle has no effect. If the pseudo handle is duplicated by DuplicateHandle, the duplicate handle must be closed."
Frankly, I've been doing serious multithreaded programming for years and have never used either call.
|
|
|
|
|
I have used GetCurrentThreadId to detect if I am calling a routine from a specific thread. If not, then the call is thunked over to the proper thread.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
[emote]Hangs head in shame[/emote]
Sigh, I missed that. Stupid me.
But the good news is that the last argument of _beginthreadex can be used to return the thread ID of the created thread. Then you can use GetCurrentThreadId and compare against the value returned in the last parameter from _beginthreadex.
Sorry about the mistake. I'll go play in traffic now.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hello,
My app is almost complete.. I went to compile it at level 4 and I get a warning "warning C4706: assignment within conditional expression" Here is the only code in my program that gives me any warnings at level 4.. How could I rewrite the following to get rid of the warning?? (I understand the warning but I am unsure of a way to rewrite the while statement...)
Any help would be greatly appreciated!
CFile fileRead;
if(fileRead.Open(m_strCurrentDir+"clients.ini",CFile::modeRead))
{
char cBuf[1024];
UINT uBytesRead = 0;
while(uBytesRead = fileRead.Read(cBuf, sizeof(cBuf)-1)) <- HERE
{
cBuf[uBytesRead] = NULL;
strBuff += CString(cBuf);
}
fileRead.Close();
}
Thanks!!
Rob
|
|
|
|
|
while((uBytesRead = fileRead.Read(cBuf, sizeof(cBuf)-1)) != 0)
This lets the compiler know you aren't crazy and that "=" is what you wanted.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Great! Thanks.. I figured it would probably be something easy like that
Thanks again,
Rob
|
|
|
|