|
Hello dear programmers,
You can see me as a beginner, actually I know only what I need to know to make an application in Visual C++. I'm having an OOP problem using MFC now.
I give you a peace of code here so you know what I mean.
But first my question: My purpose is to make pointer to a class. For example, in my clientsocket Clisocket I want in my constructorparameter a pointer to the class CSockCliDoc. In a sample code wich it works fine, it is like this:
#include <wcesock.h>
class CSockCliDoc;
class CCliSocket : public CCeSocket
{
// Attributes
public:
// Operations
public:
CCliSocket(CSockCliDoc *pInDoc);
virtual ~CCliSocket();
// Implementation
protected:
private:
CSockCliDoc *pDoc;
};
What I don't understand is the second line:
class CSockCliDoc;
What is the purpose of this part of code . I know that if you want to create a new class, you begin with "class whatever" and than "{the rest of the code for wathever it is};"
Can anybody help me to understand why the second line is needed?
Thank you very much, I'm sorry for my bad English, I'm from Holland.
|
|
|
|
|
Anonymous wrote:
class CSockCliDoc;
class CCliSocket : public CCeSocket
{
CSockCliDoc is an ahead declaration. It means "I'm going to use a pointer to CSockCliDoc in the class declaration below, but I've not declared the class itself here. It is defined elsewhere."
Anonymous wrote:
Thank you very much, I'm sorry for my bad English, I'm from Holland.
That's not an excuse, you're supposed to speak good English there
|
|
|
|
|
Thanks Johan ,
But that "ahead declaration" is that a standard C++ technique, or do they use it only in MFC?
Can you give me some links where I can get more information about ahead declaration?
I'll do my best to speak english well
|
|
|
|
|
|
Forward declaration is standard, at least in all of the C++ compilers I've used. It has nothing to do with MFC.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
You need to click faster
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Wow guys,
You are wonderful, you are really great helpers!!
Thank you very very much and may God bless you!
Peace!!
|
|
|
|
|
Hai all,
I am doing a project involving graphical drawings.
In my project, I add every drawn elements in a pointer list.
And, while drawing a new element ie on every mouse move, i redraw all the elements in the pointer list and draw the current elements with the new coordinates.
This slows down my application.
I tried Double buffering and XOR techniques but in vain.
Is there any other way to draw an element without disturbing other drawn elements?
Please help me.
With Thanks,
Arun Chakaravarthy
|
|
|
|
|
While dragging, you might want to try to invalidate only the original and new positions of the object(s) moved in the window - this way you redraw just a part of the screen.
You could also try to analyze what the bottleneck might be. I'm redrawing all of the screen in my vector editor http://www.codeproject.com/miscctrl/diagrameditor.asp[^] Hm, it starts to sound like I'm shamelessly plugging for that beast... Anyway, feel free to take a look at it and its' sibling http://www.codeproject.com/miscctrl/flowcharteditor.asp[^] - both redraw all objects as soon as one is moved, and neither of them displays any dramatic performance problems. They double buffer, btw.
If you are shuffling bitmaps, you might have another situation, but make sure that the access to the objects is as simple as possible, and that it is the drawing itself that is the problem, before you start optimizing the drawing rect.
|
|
|
|
|
Is there a function to find the differences between two time structs of type _timeb ? If not, is there any easy way to show atleast the hundreth's of seconds between to time_t values?
Whenever I do something below I always get 0's, it can't always be that exact:
double diff;
diff = difftime(end, start);
char msg[] = "blah blah blah runtime %.10f second(s).";
- Nick Parker My Blog | My Articles
|
|
|
|
|
time_t only has 1-second resolution, so you'll never get a different less than 1 second (unless it's 0). Your best bet would probably be to use FILETIME , which is a 64-bit number with 100ns resolution. It's a plain number so calculating differences is easy. (I think the CRT time structs are incredibly clunky and I avoid them as much as possible.)
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Laugh it up, fuzzball.
|
|
|
|
|
Thanks Mike, are there other functions other than GetFileTime that you would suggest, I am not working with files so I won't have a HANDLE for it?
Nevermind, I think SystemTimeToFileTime should work. Thanks again for pointing me in the right direction.
- Nick Parker My Blog | My Articles
|
|
|
|
|
First off apols if this is in the wrong section i am new here
I have this code now and try as i may i cannot get the random number to change it is always 41 when it should be between 0-100. I am not that good at C++ and would appreciate any help can i please reinforce the basis that my knowledge is very basic thanks for any help guys.
#include <iostream.h>
#include <stdlib.h>
int main(void)
{
// declare our variables
// Guess entered by user and random number
int guess, random;
random = rand();
// Creates a loop for the main program
do
{
cout << "My High-Low game!\n\n";
cout << "Please enter a number between 0 and 100: ";
cin >> guess;
cout << "You entered " << guess << "!\n";
if (guess == random)
{
cout << "Correct guess, the answer is " << guess << "!\n";
}
else
{
if (guess > random)
{
cout << "Your guess is too high!\n";
}
else
{
cout << "Your guess is too low!\n";
}
}
// Terminating condition for the loop
// Program stops when the guess equals the random number
}
while(guess!=random);
// This command pauses the program
system("PAUSE");
return 0;
}
This Better ******* Work!
|
|
|
|
|
Put the line
random = rand();
in the do while block
and better add this to the start of the main
srand(time(NULL));
this way the seed is randomly generated too
(you wont start with the same population over and over again)
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
You need to call srand() first, otherwise rand() will always return the same number. A line like
srand((unsigned)time(NULL));
before the call to rand() should do the trick.
|
|
|
|
|
To elaborate a bit more on the previous response, it is recommend that you first seed the random number generator. If you wish a consistent pattern of values then always seed with the same value. If not then you can use this :
srand( time(NULL) % RAND_MAX );
to obtain values between 0 and 100 then you can do this :
random = rand() % 101;
The modulus operator returns the remainder of the division operation of the two numbers. This has the effect of clamping the return value between 0 and one less than the dividend.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
rand() returns pseudo random numbers rather than real random numbers. This is why you always get the same value. You can work your way around this by setting the random seed, before you invoke rand(). Seed is a number which is used inside the rand() function to produce the sequence of these pseudo random numbers.
So, different seed value gives you different sequence of numbers. Common trick is to give the current time as seed number as this gives you a different sequence each time you run your application. You can set the seed like this:
srand(static_cast<unsigned>(time(0)));
Make this function call before you use rand() for the first time.
If you wan't the numbers be in a spesified range (between 1 and 100) you must use the following line instead of just invoking rand().
random = 1 + (rand() % 100);
rand() returns numbers between 0 (?) and RAND_MAX (== big number, depends on you compiler I think) and the above line takes a modulus from the returned value and this conveniently scales the result between 0 and 99.
Hope this helps,
Cohen
|
|
|
|
|
Thank you for the tips guys i will try them out i just have to figure a way fo getting it to give the user 8 trys max. Thanks for not talking to clever for me lol
This Better ******* Work!
|
|
|
|
|
bobski2200 wrote:
i just have to figure a way fo getting it to give the user 8 trys max.
Change
while(guess!=random); to
while(guess!=random && num_tries < 8); Start num_tries at 0 and increment it after each guess.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Graham - Slow
Rick - Slower
Cohen - Slowest
|
|
|
|
|
Hi!
I've got a struct which needs to be byte swapped, so I figured, why not overload the conversion functions to take my struct as a param, byte swap the fields, then return a new struct. However, I keep getting an error that the compiler doesnt know how to convert one parameter 1 (of htons) from unsigned int to myStruct. Below is my code:
typedef struct
{
u_8 protocol_id;
u_8 msg_type;
u_16 length;
} FrameHdr;
_inline FrameHdr ntohs (FrameHdr i_param)
{
FrameHdr mObj;
mObj.length = ntohs (i_param.length);
return (mObj);
}
The compiler error is:
error C2664: 'ntohs' : cannot convert parameter 1 from 'unsigned short' to 'FrameHdr'
I tried adding 'const' at the end of the function definition but that didnt work either.
Any ideas?? TIA!
-C
|
|
|
|
|
typedef struct FrameHdr
{
u_8 protocol_id;
u_8 msg_type;
u_16 length;
FrameHdr ntohs (FrameHdr i_param);
} FrameHdr;
FrameHdr FrameHdr::ntohs (FrameHdr i_param)
{
FrameHdr mObj;
mObj.length = ::ntohs (i_param.length);
return (mObj);
}
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I cannot add a function definition to my struct. The structs are used for data to send in a msg and in byte aligned etc.
Any other way of doing this w/o adding a function definition to my struct?
Thanks.
-C
|
|
|
|
|
Why not a wrapper to your structure
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I know there's a much simpler answer to this. I only want to overload a function and its not letting me. I only want a simple solution to this compiler error. Thanks.
-C
|
|
|
|