|
I recently saw something like this, and was wondering what's the benefit.
struct MyStruct
{
// etc.
};
Later on in the program, I saw:
struct MyStruct* pMyStruct;
===================
What's the point of using the 'struct' keyword (a second time) to define a pointer to a structure that's already defined? It compiles fine, but what purpose does it serve?
Any sensible explanation will be appreciated.
William
Fortes in fide et opere!
|
|
|
|
|
It was required in C, but not in C++. Old habits die hard, I guess.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
You see quite a bit of C-style coding in C++. And I find that it just makes maintaining C++ even more horrible than it actually is.
Kevin
|
|
|
|
|
Yep. I cringe whenever I run across the old
typedef struct StructName {
} StructName; that I used to have to do in C all of the time.
Software Zen: delete this;
|
|
|
|
|
Hi,
I´m using VS.NET 2003 and I´m having some odd linking errors and I would appreciate if anyone could explain to me why, and how I could solve this.
I´ve done this simple example to show you what I mean.
car.h<br />
#pragma once<br />
#include <iostream><br />
using namespace std;<br />
<br />
void decfunc();<br />
char *msg;
car.cpp
#include "car.h"<br />
<br />
void decfunc()<br />
{ <br />
msg = new char[12];<br />
msg = "Hello world!";<br />
}
main.h
#include "car.h"<br />
using namespace std;
main.cpp
#include "main.h"<br />
<br />
void main()<br />
{<br />
decfunc();<br />
cout << msg;<br />
}
The link errors I receive are:
tests error LNK2005: "char * msg" (?msg@@3PADA) already defined in main.obj
tests fatal error LNK1169: one or more multiply defined symbols found.
Thanks!
|
|
|
|
|
add following lines to car.h:
#if !defined(_CAR_H)
#define _CAR_H
...
your previous code
...
#endif
so char*msg will be defined only once.
I hope it will help
Marcin Wojciechowski
|
|
|
|
|
Hi Marcin, thanks for your reply
acctualy, it didnt work. My car.h now looks as follows:
#if defined(_CAR_H)<br />
#define _CAR_H<br />
<br />
#include <iostream><br />
using namespace std;<br />
<br />
void decfunc();<br />
char *msg;<br />
<br />
#endif
and I still get the same link errors
error LNK2005: "char * msg" (?msg@@3PADA) already defined in car.obj
fatal error LNK1169: one or more multiply defined symbols found
I´m having a hard time seeing what makes it being defined twice.
Does it have something to do with the decfunc-function perhaps?
|
|
|
|
|
In car.h:
extern char *msg;
In car.cpp:
char *msg = NULL;
...cmk
Save the whales - collect the whole set
|
|
|
|
|
great! Thanks.
humpa humpa
|
|
|
|
|
I want to write a program to show a BMP , which is so big that the PC has not enough memory to load , can you give me some clews ? if you have the code please mail me , thanks a lot .
|
|
|
|
|
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
void optimization(double x[3][2]);
double power(double x,int n);
double F(double x[2]);
double fun(double x[3][2],double xm[2] );
double a,k,b,v,E,p,q,y;
double x[3][2],fx[3],*xh,*xl,*xg;
double temp,fxh,fxl,fxg,fxm,fxr,fxe,fh1,fxc;
double xm[2],xr[2],xe[2],xh1[2],xc[2];
void main()
{
cout<<"输入边长值:"; cin>>a; cout<<"输入反射系数:"; cin>>k; //输入原始数据
cout<<"输入收缩系数:"; cin>>b; cout<<"输入扩伸系数:"; cin>>v;
cout<<"输入容差:";cin>>E; cout<<"输入的初始顶点:";
cin>>x[0][0]>>x[0][1];
p=(sqrt(2+1)+2-1)*a/(sqrt(2)*2); q=(sqrt(2+1)-1)*a/(sqrt(2)*2); //建立初始单纯形
x[1][0]=x[0][0]+p; x[1][1]=x[0][0]+q; x[2][0]=x[0][0]+q; x[2][1]=x[0][0]+p;
optimization(x);
}
double F(double x[2])
{
double f;
f=3*power(x[0],2)+power(x[1],2)-12*(x[0])-8*(x[1]);
return f;
}
double power(double x,int n)
{
int i; double p=1.0;
for(i<1;i<=n;i++)
p=p*x;
return p;
}
void optimization(double x[3][2])
{
fx[0]=F(x[0]); fx[1]=F(x[1]); fx[2]=F(x[2]);
for( int i=0;i<3;i++)
{
for(int j=1;j<2-i+1;j++)
{
if(fx[i]<=fx[i+j])
{
temp=fx[i];
fx[i]=fx[i+j];
fx[i+j]=temp;
}
}
fxh=fx[0]; fxg=fx[1]; fxl=fx[2];
}
for(i=0;i<3;i++)
{
if(F(x[i])==fxh) xh=x[i];
if(F(x[i])==fxg) xg=x[i];
if(F(x[i])==fxl) xl=x[i];
}
xm[0]=(xg[0]+xl[0])/2; xm[1]=(xg[1]+xl[1])/2; fxm=F(xm); // 计算反射中心
xr[0]=(1+k)*xm[0]-k*xh[0]; xr[1]=(1+k)*xm[1]-k*xh[1];fxr=F(xr); //计算反射点
if(fxr>=fxl&&fxr<fxg)
{
="" xh[0]="xr[0];xh[1]=xr[1];
" if(fun(x,xm)<e)
="" cout<<"最优解为:"<<xm[0]<<endl<<"最小值为:"<<fxm<<endl;
="" else="" optimization(="" x);
if(fxr<fxl)
="" xe[0]="(1-v)*xm[0]+v*xr[0];
" xe[1]="(1-v)*xm[1]+v*xr[1];
" fxe="F(xe);
" if(fxe<fxr)
="" xh[1]="xe[1];
" if(fun(x,xm)<e)=""
="" optimization(x);
="" }
="" else
="" }
="" if(fxr="">=fxg)
{
fh1=fxr<=fxh? fxr:fxh;
if(fxr<=fxh)
{
xh1[0]=xr[0];xh[1]=xr[1];
}
else
{
xh[0]=xh[0];
xh1[0]=xh[1];
}
xc[0]=(1-b)*xm[0]+b*xh[0];
xc[1]=(1-b)*xm[1]+b*xh[1];
if(fxc<=fh1)
{
xh[0]=xc[0];
xh[1]=xc[1];
if(fun(x,xm)
|
|
|
|
|
While you failed to indicate what mistakes needed correcting, I would suggest using more meaningful names than x, y, z, and variants thereof. Your code is next to impossible to read.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
i make one program for ivrs purpose.in which for database connectivity i use CRecordSet class fuction .in which i access 6 TABLES at a time for data manipulation. at this time cpu goes 100% and upto 15 seconds exe hangup.so another user dont able to access this exe file .so plz tell me can i make data retrival fast by any other method
|
|
|
|
|
Hi
I suggest u to use another Thread for database retrival while ur main msg loop handle user and system msgs.
also if u make a single QUERY for 6 table if it is possible it make ur jobs faster.
Bye
|
|
|
|
|
I need:
*) Get Handle of Main Window from process handle (I know the process handle).
or:
*) Get process info (i.e. process ID or handle) from a Window handle (I know the window handle).
any solution for 2 questions above is helpful - first is prefered.
thx
includeh10
|
|
|
|
|
Answer to your 2. question:
DWORD dwProcessId = 0;<br />
GetWindowThreadProcessId (hWnd, &dwProcessId);<br />
HANDLE hProcess = NULL;<br />
hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, dwProcessId);
|
|
|
|
|
1.
- Use GetProcessId() to get process id from process handle.
- Use EnumWindows() to look at each top-level window.
- For each top-level window call GetWindowThreadProcessId() to get the thread id and process id that was used to create the window.
- Break when you find a top-level window that was created by the specified process handle/id.
2.
- Use GetWindowThreadProcessId() to get the thread id and process id that was used to create the window.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi Guys,
I'm using my app's OnIdle() to monitor a list of CTime objects that are essentially alarm times(these can range from a few seconds in the future to weeks or months in the future). I decided on OnIdle() because I didn't want this monitoring to slow down the main app but also was too lazy to implement a new thread.
However, the OnIdle() calls seem to take too low a priority for my liking! When the application is running in the background it doesn't even seem to get called at all. Do I need to set some kind of priority to my app?
Many thanks,
Simon
|
|
|
|
|
srev wrote:
When the application is running in the background it doesn't even seem to get called at all.
I'd say that's by design and also a good thing. Why not setup a timer that's fired once a second or however often you need to test and when it fires run through the list. Or use a thread or probably best of all waitable timers.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Thanks for the response Neville. I'll definitely look into waitable timers. Reall useful advice, thanks again.
Simon
|
|
|
|
|
I found problem with CSocket when I use it for voice communication in LAN. After a long time the server program and the client program hangs. If I end task one of them then the other will become fine. I use the methods Send and Receive for data transfer.
What will be cause of this problem???
Please help me!
Thanks in advance!
|
|
|
|
|
My program can not use the mouse, And all the operation will be done by the keyboard. But I do not know how to get the ID number of the item which has the keyboard focus.
Thanks!
|
|
|
|
|
pantao551 wrote:
item which has the keyboard focus.
Use GetFocus() to find the Ctrl which currently under the Keyboard Focus.
pantao551 wrote:
how to get the ID number
Pass the HWND or CWnd return from call of GetFocus to GetDlgCtrlID which will return the Numeric ID of Control!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
What Alok said, with the addition that you can use int id = ::GetWindowLong(::GetFocus(), GWL_ID); if you'd like to stay win32.
--
Schni Schna Schnappi! Schnappi Schnappi Schnapp!
|
|
|
|
|
Hi, is it any way I can send a packet using an specific port?, for example, what would I have to do if I want to send a packet using the source port xxxx?
Thx in advance
Vertigo
Real Programmer isn't who just knows how to use a programming tool, Real Programmer is who knows how to write cool stuff in any language, 'cuz he/she/(it!!?) thinks like a machine .
|
|
|
|