|
That's because of the new line (character "\n") that you entered in previous cin, to fix this problem simply add statement "cin.ignore(1, '\n');" before the second use of cin. Example:
<br />
int x;<br />
float y;<br />
cin >> x;
cin.ignore(1, '\n');
cin >> y;
|
|
|
|
|
Hi, everyone!
In one of my class(CClassA), I have declare a member variable of my B class( CClassB). How to access the CClassA from CClassB?
Best Regards,
Wayne King
20 May 2002
|
|
|
|
|
You'll need to add a pointer to CClassA as a member of CClassB
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Hi, nish!
This is exactly what I did. But I got a lot of compile error.
I found the reason is the header file of class A & B must include each other. During compiling time the compiler seems not able to determine who's who? ( Chick/Egg problem )
Any idea on this issue?
Best Regards,
Wayne King
20 My 2002
|
|
|
|
|
Instead of doing the cross include, do a forward declaration. IF class A needs to know what class B is, and vice versa, simply do the #include in the .cpp files, and in the header, do this
Class A.h
class B;
class A
{
...
and vice-versa.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian,
Try your method without success. But later I put class A and class B in the same file. The problem solved.
// Header file:
class A;
class B;
class B
{
A m_variable;
}
class A
{
B m_variable;
}
In the above header file, the sequence is very important. class B must be defined before the class A.
Is it possible to separate class A and class B into different file?
Best Regards,
Wayne King
|
|
|
|
|
It depends on how you're accessing class B. If it's by pointer or reference, then you only need to provide A with a forward declaration of B:
class B;
class A
{
private:
B* m_pB;
B& m_b;
};
This is because you're only declaring B as a pointer or reference, which are always 4 bytes (in Win32), so the compiler doesn't need anymore information to determine the size of A.
If you were going to declare an instance of B directly inside of A, then the compiler would need to know how big B is so that it could add it to A's size. For that, the compiler needs B's definition. So you need to put B's definition on top of A, which is typically done by including the header file where it's defined (B.h):
#include "B.h"
class A
{
private:
B m_b;
};
I hope to have shed some light on this stuff.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
Alvaro,
Thanks very much. Your answer is very informative. It not only solve my annoying problem, it also give me an answer why this thing happen and how to avoid them. Thanks again.
Best Regards,
Wayne King
|
|
|
|
|
I have a dialog with a list control in it and a handler for the LVN_COLUMNCLICK notification. In the handler I am displaying a modal dialog, the problem is that this dialog does not initially have the focus, I have to click on it once to activate it. But it gets worse..... if I click outside the dialog on the list control header in the background window then I get another dialog popup! (the header click handler is being called again)
What is going on here? I did a test and moved the dialog display into the NM_CLICK notification of the list control and all works ok, seems to be some problem with popping up a dialog in the header click notification.
|
|
|
|
|
The header will capture the mouse when it is clicked, so that drag&drop can be detected (if the header is dragged, LVN_COLUMNCLICK will not be sent). To avoid the problem you're seeing, you can call ::SetCapture(NULL); prior to displaying the dialog.
--------
From now on we can call C# and MC++ "The square wheel languages" -- Jack Handy, The Lounge
|
|
|
|
|
|
Hi,
Is there a relatively straightforward way of determining the video card? I am creating a small settings panel for a game, and want the video card to appear in a listbox. I figure I probably need to use DirectX to find out the video card driver. Any pointers as to how to do this would be much appreciated.
Many thanks,
Keith
|
|
|
|
|
If you simply want a list of the display devices currently installed on the system, then you can use EnumDisplayDevices .
If you would like to get more complicated and list all of the display modes that each of the devices that each display adapter supports, then there is a really nice example program that does this in the DirectX 8.0 SDK.
Good Luck!
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Many thanks for your reply, EnumDisplayDevices sounds exactly what I need. Unfortunately, I have tried to use it but I get a compile error:
EnumDisplayDevices: Undeclared Identifier
I have inluded user32.lib and the windows.h header, and the autotext in VC++ seems to recognise the function, but it just won't compile.
If anyone has any ideas of why this might be, I would be very grateful.
Again, many thanks,
Keith
|
|
|
|
|
It says in MSDN that the function is only available in Win98, Windows 2000 or above. That means that you will have to define the version that you would like to compile for to include the version 5 function headers. make this definition at the top of your stdafx.h file:
#define WINVER 0x0500
but once again, this will make you program so that it will not work on windows 95. Hopefully this is acceptable.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
BTW, it will also not work on Windows NT 4.0, as this is a version WIN OS as well.
Good Luck.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I have a function: CString GetNextString( ifstream &InFile )
This works fine, but it seems everytime I get an error(such as a missing semicolon) I get another error that says it doesn't understand what an ifstream is. So I have to deleted the GetNextString function, comment out all calls to the GetNextString function, build it without any errors, then recreate the GetNextString function. It's a big hassel. Can it be fixed?
-Raffi
|
|
|
|
|
This is most weird, I'd bet the problem lies elsewhere. Things to check:- Are you including
using namespace std; ? If not, you should replace ifstream with std::ifstream throughout.
- What header are you using (should be
<fstream> ) and where are you including it?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Here's the declarations and functions i use, when i get to EnumObjects, it comes with an "Unhandled exeption" error and stops at that line.
IShellFolder *pSf = NULL;
LPENUMIDLIST pEidl;
pSf->EnumObjects(ghWnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &pEidl);
ghWnd is the handle to my window and it is valid, i have tested that.
Anyone know whats wrong?
Thankyou
|
|
|
|
|
I guess this is not the exact code you're using, since pSf is null.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Sorry, here's the definition of pSf;
LPSHELLFOLDER pSf;
|
|
|
|
|
I mean, maybe it is the way you're obtaining this pSf what it's wrong. Have you checked it is not null before calling EnumObjects on it?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
It looks real bad. Could you post the code you're using to retrieve pSf ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Heh, woops called the wrong function to set the pSf, i have to call
SHGetDesktopFolder (&pSf); thanks for the help :=)
|
|
|
|