|
You need some understanding of C++.
use a baseclass from which graphic_card and mother_board will be derived from.
for example
class Mother_board :public Base
and
class Graphic_card :public Base
Then
Base *base;
Mother_board *mBoard;
Graphic_card *gCard;
<<<assumeing that="" the="" mboard="" and="" gcard="" are="" initialed.="">>>
then
base = mBoard or <<< you can use reinterpret_cast too >>>
base = gCard is valid assignmnet.
add virtual or pure virtual methods in both base and derived class so that you can call the methods as base->foo();
-Prakash
|
|
|
|
|
reinterprit_cast
is the key word
but its not that simple
as u feel as c++ doesnot
like such type casting and
might lead u some error in
programe if reiterprit is not
used with proper cution .
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
dynamic_cast can be used for better safety.
-Prakash
|
|
|
|
|
The applicaiton is ok in Windows 2000.
When run in Windows Xp ,at the beginning there is a error which said the memory could not be visited.
I link WS2_32.LIB in the project.
Why?
Thanks!
|
|
|
|
|
rushing wrote: The applicaiton is ok in Windows 2000.
Is it your application?
Is it memory exeception? if it is written by you can u identify the code from where the memory exception is raised?
-Prakash
|
|
|
|
|
I just realized the Point class does not provide the = operator. Now that I'm trying to actually use GDI+ in my apps, I'm finding the classes for Rect, RectF, Point, and PointF to be rather peculiar in design.
Also, Rect doesn't provide functions that return the endpoints.
I can't create an Array of Point and copy another Point into one of it's elements (unless it's during initialization). Instead, I have to resort to assigning the X and Y members explicitly into each array element.
I'm not sure if there is some bigger picture I'm missing here or some new highly ultra OOP paradigm I missed the whitepaper on or if this design is just weak and missing some of the useful operators that MFC provided on many of it's classes.
Does anyone have any insight concerning these omissions in some of the more basic classes like Point and Rect? My code just looks rather bloated copying the members individually like this so I thought maybe I'm doing it wrong.
Thanks in advance for any guidance.
-- modified at 21:59 Saturday 7th January, 2006
|
|
|
|
|
I want to build a win32 console program in VC .Net. I wrote one function in random1.h and random1.cpp, Then, I wrote my main program in SimMCMain.cpp which call this function from random1.h and random1.cpp. It's no problem in VC++ 6.0, but it always has problem when linking in VC.Net. Can anyone give me some suggestion? Thanks
****random1.h***
#ifndef RANDOM1_H
#define RANDOM1_H
double GetOneGaussianBySummation();
double GetOneGaussianByBoxMuller();
#endif
****random1.cpp****
#include <cstdlib>
#include <cmath>
// the basic math functions should be in namespace
// std but aren't in VCPP6
#if !defined(_MSC_VER)
using namespace std;
#endif
double GetOneGaussianBySummation()
{
double result=0;
for (unsigned long j=0; j < 12; j++)
result += rand()/static_cast<double>(RAND_MAX);
result -= 6.0;
return result;
}
double GetOneGaussianByBoxMuller()
{
double result;
double x;
double y;
double sizeSquared;
do
{
x = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
y = 2.0*rand()/static_cast<double>(RAND_MAX)-1;
sizeSquared = x*x + y*y;
}
while
( sizeSquared >= 1.0);
result = x*sqrt(-2*log(sizeSquared)/sizeSquared);
return result;
}
****SimMCMain.cpp ****
// requires Random1.cpp
#include <Random1.h>
#include <iostream>
#include <cmath>
using namespace std;
double SimpleMonteCarlo1(double Expiry,
double Strike,
double Spot,
double Vol,
double r,
unsigned long NumberOfPaths)
{
double variance = Vol*Vol*Expiry;
double rootVariance = sqrt(variance);
double itoCorrection = -0.5*variance;
double movedSpot = Spot*exp(r*Expiry +itoCorrection);
double thisSpot;
double runningSum=0;
for (unsigned long i=0; i < NumberOfPaths; i++)
{
double thisGaussian = GetOneGaussianByBoxMuller();
thisSpot = movedSpot*exp( rootVariance*thisGaussian);
double thisPayoff = thisSpot - Strike;
thisPayoff = thisPayoff >0 ? thisPayoff : 0;
runningSum += thisPayoff;
}
double mean = runningSum / NumberOfPaths;
mean *= exp(-r*Expiry);
return mean;
}
int main()
{
double Expiry;
double Strike;
double Spot;
double Vol;
double r;
unsigned long NumberOfPaths;
cout << "\nEnter expiry\n";
cin >> Expiry;
cout << "\nEnter strike\n";
cin >> Strike;
cout << "\nEnter spot\n";
cin >> Spot;
cout << "\nEnter vol\n";
cin >> Vol;
cout << "\nr\n";
cin >> r;
cout << "\nNumber of paths\n";
cin >> NumberOfPaths;
double result = SimpleMonteCarlo1(Expiry,
Strike,
Spot,
Vol,
r,
NumberOfPaths);
cout <<"the price is " << result << "\n";
double tmp;
cin >> tmp;
return 0;
}
|
|
|
|
|
Pierre,Hsieh wrote: but it always has problem when linking in VC.Net.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
SimpleMCMain1 error LNK2019 and
SimpleMCMain1 fatal error LNK1120
|
|
|
|
|
You really should supply more relevant information if you want useful help in solving your problem. Most people do not like playing "twenty questions" just to get enough information to help.
When the linker generates LNK2019 it gives you more info, what is the information given?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Sorry, Because my system is chinese version and this is my first time to ask question in web site, that's why I didn't provide more information. I checked this error message from MSDN web site.
LNK2019 : unresolved external symbol 'symbol' referenced in function 'function'
SimpleMCMain1 error LNK2019: 無法在外部之程式庫中找到或連結所需之資料型別或函式的符號 _main,於函式 _mainCRTStartup 中參考
LNK1120 : number unresolved externals
SimpleMCMain1 fatal error LNK1120: 1 個無法在外部程式庫中找到或連結所需之資料型別或函式
|
|
|
|
|
What is SimpleMCMain1 ? It's not shown anywhere in your code.
Are you creating a CRT application? The LNK2019 linker error might be resolved by changing "Minimize CRT Use in ATL" to "No". Go to Project Properties / Configuration Properties / General. Does that help?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
The application that I am currently developing is attempting to programmatically control an external application by simulating mouse clicks in it's various windows. I have managed to produce the context menu on the external application by simulating a RH mouse click (using PostMessage's with WM_RBUTTONDOWN / WM_RBUTTONUP). I can also execute an item on the popup menu by positioning the cursor and simulating a LH mouse click (using PostMessage's with WM_LBUTTONDOWN / WM_LBUTTONUP). This all works as expected if there is no other code following it (i.e. my app exits) or there is an AfxMessageBox separating this code and further mouse-click simulations. The failure is that execution of the popup menu item doesn't result in a new window. I get the feeling that the external app is not getting 'time' to receive/react to the simulated clicks until my app exits (Presumably, the AfxMessageBox must also have the same effect - yes ?). I have tried Sleep(10000) after the context menu operation, but this doesn't seem to help. Do I need to (somehow) inform the system that my app doesn't need the remainder of it's current timeslot, thus giving the external app time to "do its stuff". If so, how do I do that ?
Doug
|
|
|
|
|
Does the blocking SendMessage(...) instead og PostMessage help?
Vipin - MVP
|
|
|
|
|
Tried SendMessage originally, and couldn't even get the initial stages to work. I have currently got this stuff implemented in InitDialog() of a dialog-based app - and I was in error in my original posting when I said that it only worked when my app exited - I should have said that it only worked once the DoModal() had executed. Is this a clue ??
Doug
|
|
|
|
|
Assuming you can get the process handle (if your app launched the other app with ::CreateProcess(), for instance), after posting the mouseclick message, try using ::WaitForInputIdle(processHandle, timetowait) like so:
bool bIdle = false;
DWORD dwWaitResult;
dwWaitResult = ::WaitForInputIdle(hProcess, 5000);
switch (dwWaitResult)
{
case 0 :
{
bIdle = true;
}
break;
case WAIT_TIMEOUT :
{
AfxMessageBox("Timed out waiting for idle state.");
}
break;
case WAIT_FAILED :
{
}
break;
}
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-- modified at 9:00 Sunday 8th January, 2006
|
|
|
|
|
Hi John and VIP ! Thanks for your input - in the meantime, I seem to have solved the (current !) problem - putting my code in InitDialog() seems to be the wrong place. Thinking about it, I suspect that the message loop (pump) is not activated until window initialisation has been completed. I've moved my code into InitInstance() (and actually removed the main window dialog and DoModal() as I currently don't need it !) and everything now works !!! Thanks again ! Perhaps someone can confirm my suspicions about the message loop and InitDialog() - might help someone else in the future !
Doug
|
|
|
|
|
|
|
You need to make composite activex control.
-Prakash
|
|
|
|
|
i am previously ask this question before but i have relise taht my previous question was not easy to understand.
can any one please teach me how i can pass a object to a function using pointers?
this is normally how i pass a normal variable to a function using a pointer:
<br />
void function(int* ptr)<br />
int main()<br />
{<br />
int num1;<br />
function(&num1);<br />
<br />
return 0;<br />
}<br />
wat i wanan do now is something like this:
<br />
class theclass<br />
{<br />
public:<br />
<br />
}<br />
void function(theclass* ptr)<br />
<br />
int main()<br />
{<br />
theclass tc;<br />
function(&tc);<br />
<br />
return 0;<br />
}<br />
so what i am trying to do is replacing the int with the object but it have error so could any one please teach me how to do this??
i will greatly appreciated it![Rose | [Rose]](https://codeproject.freetls.fastly.net/script/Forums/Images/rose.gif)
|
|
|
|
|
What is the error that you are getting ?
-Prakash
|
|
|
|
|
this is part of my actual code:
<br />
void add_new_item(grahpic_card* gc_add);<br />
<br />
int main()<br />
{<br />
graphic_card gc;<br />
add_new_item(&gc);<br />
}<br />
:\Documents and Settings\nick\Desktop\lalabear project\newporject.cpp(128) : error C2065: 'grahpic_card' : undeclared identifier
C:\Documents and Settings\nick\Desktop\lalabear project\newporject.cpp(128) : error C2065: 'gc_add' : undeclared identifier
C:\Documents and Settings\nick\Desktop\lalabear project\newporject.cpp(128) : error C2182: 'add_new_item' : illegal use of type 'void'
C:\Documents and Settings\nick\Desktop\lalabear project\newporject.cpp(160) : error C2064: term does not evaluate to a function
C:\Documents and Settings\nick\Desktop\lalabear project\newporject.cpp(181) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
|
|
|
|
|
neodeaths wrote: :\Documents and Settings\nick\Desktop\lalabear project\newporject.cpp(128) : error C2065: 'grahpic_card' : undeclared identifier
neodeaths wrote: graphic_card gc;
are you sure ur class name is graphic_card and not grahpic_card (spelling mistake)
-Prakash
-- modified at 11:10 Saturday 7th January, 2006
|
|
|
|
|
wow your rite!
it works now!!
thank you for your help
|
|
|
|