|
Server.h
class TcpServer
{
...
private:
static map<SOCKET, TcpServer> m_instances;
...
};
When I build this, the compiler reports this:
error C2079: 'std::pair<_Ty1,_Ty2>::second' uses undefined class 'TcpServer'<br />
with<br />
[<br />
_Ty1=const SOCKET,<br />
_Ty2=TcpServer<br />
]
Any solution?
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
This is a circular definition - you are trying to use TcpServer inside of itself. You might be able to make the map take a pointer and get it to work:
private:
static map<SOCKET, TcpServer*> m_instances;
An expert is somebody who learns more and more about less and less, until he knows absolutely everything about nothing.
|
|
|
|
|
You just stumbled onto infinity, believe it or not.
When the C++ compiler finds a struct or a class it needs to know the size of it, so that it can allocate correct memory buffers to store the objects in. So when it finds a struct, it goes through each member variable, summing up the size of each member. That's the size the struct will get (not considering alignment issues, but that's not important in this case). Simple addition basically.
So consider this struct:
struct X {
X x;
} What is the size of objects of type X? It's the size of x. So, what's the size of x? Since it's of type X, it's the size of objects of type X. What is the size of objects of type X? ... and so on.
Do you see the infinite recursion here? X depends on itself, and thus its size is undefined, and is rejected by the compiler as an undefined type. A type in C++ is not complete (undefined as the compiler said) unless its size is known.
Navin suggested you could use pointers instead. How does that help you might wonder? The easy answer is that pointers on most platforms come in one size only (this is not entirely true, as old DOS programmers can testify, but don't worry about that for now). On a 32-bit compiler, pointers are typically 4 bytes large. 32 bits = 4 * 8 bits = 4 * 1 bytes. So, by using pointers instead, the compiler can determine the correct size.
--
Arigato gozaimashita!
|
|
|
|
|
I could use a pointer, but what I really don't understand is when a person I met on IRC tried to compile some example code in VC++ 7.1, and it didn't report any errors. I use VC++ 7.0.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
when a compiler compiles != valid code
For your specific problem of looking up a socket object from an socket handle, I would stick with the pointer solution. You probably don't want to waste memory by storing a copy of the whole object in the container.
|
|
|
|
|
I'm working with threads and using GetExitCode. It supposedly returns STILL_ACTIVE but I couldnt find its value in any .h file in the VS folder. The only file it was mentioned in is winbase.h and there its a typedef statement, not a #define.
?
Thanks,
sb
|
|
|
|
|
Hello,
Can someone tell me what the class name of a dialog box is?
The problem is I need to find a specific window and the only two things I know are:
- it is a dialog box (modeless);
- and its window title (static-never-changing string);
Also, if you think there is a better (more correct) way of doing this, please do let me know!
Thank you,
Dave
|
|
|
|
|
About using spy++ and drag the dialog application to spy++ window.
|
|
|
|
|
dNimrod#X wrote:
Can someone tell me what the class name of a dialog box is?
#32770
dNimrod#X wrote:
Also, if you think there is a better (more correct) way of doing this, please do let me know!
By sending a window a WM_GETTEXT message, you risk entering a deadlock state if that window is in a blocked state (i.e., its message pump is not processing messages). I'm not saying that will happen to you here, but it is something you need to consider.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
dNimrod#X wrote:
Can someone tell me what the class name of a dialog box is?
You should try the excellent Spy++ tool which comes with visual studio. It's called spyxx.exe, and it lets you inspect any window. Just hit ALT+F3 when it's started, and a dialog with blue/white icon will show up. Just drag the icon onto any window it'll highlight the window you selected in the tree view. Double click the treeview item or right click it. You can even spy on window messages for any window which is really handy sometimes. Have fun exploring!
--
Arigato gozaimashita!
|
|
|
|
|
U can use the SPY++ utility which comes with VC++ to get these informations
|
|
|
|
|
I have seen this done in a program I don't remember which, where the program woud allow you though and option to show or hide all icons on the desktop.
You can accomplish this manually in WinXP by right clicking on the desktop and selecting
Arrange Icons By | Show Desktop icons.
I have searched everywhere and how not found any info on the subject.
So, please how do you do this programmatically?
Thanks,
|
|
|
|
|
Hai,
I'm new to C++.I'm declaring a function and using it in main.cpp. If I want to use that function in my class say class1.cpp..how should I do that.
Thanks.
|
|
|
|
|
Hello,
If you want to associate the function with the class, exemple use data members from the class without passing them as arguments, make the funtion a member function of the class:
<br />
class A<br />
{<br />
public: <br />
void YourFunction();<br />
};<br />
If you want to call that function from a member function (say constructor) you can do this (there's nothing special about it...)
<br />
A::A()<br />
{<br />
YourFunction();<br />
}<br />
Hope this helps..
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
Hai ..
Thanks o lot..but i think my question is different ..I'm declaring the function in main.
it's somewhat like this..
void myfuntion()
main()
{
..
myfunction();
}
myfunction()
{
...
}
class A
{
public:
void mysecondfunc();
}
void A::mysecondfunc()
{
myfunction(); --->if I use like this it is giving error identifier undeclared, not found
}
how should resolve this..
Thanks again.
|
|
|
|
|
Hello,
In that case, you simply need to declare the function before you use it. The most common case would be in a header file. The implementation is done in the corresponding .cpp file. For exemple:
Consider your function MyFunc, in the header file (say MyHeader.h) you declare the function like this: void MyFunc();
You define the function in the implementation file say MyFunc.cpp like this:
<br />
void MyFunc()<br />
{<br />
}<br />
Whenever you want to use MyFunc, just include MyFunc.h at the top of the file where you use the function.
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
Hai,
Thanks again..I tried this..but it gives an error that func redefined or already defined in obj..what am I missing here..
Thanks a lot.
|
|
|
|
|
Delete all the .obj files and do a completely rebuild the project...
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
You probably still have a prototype at the top of main.cpp . If that is the case, delete the prototype and replace it with a #include statement instead.
You'll then need to modify the .h file so that it gets included only once. Check out the .h files that ClassWizard produces to see the directives that are used.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi,
I used next code:
<br />
if(labMask.hideemptyrows == true){<br />
mc_hideemptyrows.SetCheck(BST_CHECKED);<br />
OnCheckHideemptyrows();<br />
}
else{<br />
mc_hideemptyrows.SetCheck(BST_UNCHECKED);<br />
}
strange thing is: when labMask.hideemptyrows = true, the "else" statement is performed !!!
if I do this:
if(labMask.hideemptyrows){ ... }
then it works fine.
Can anyone tell me why this is?
tnx.
(oh btw labMask.hideemptyrows is of type bool)
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
What type is hideemptyrows ? Using a breakpoint at the if(...) statement, what value does it have?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I had the same problem a couple of weeks ago, and finally realized that I was stepping through the code in 'Release' mode. So the values it was giving me weren't correct. You may not be doing the same thing, but just to make sure, check and see if you're in debug mode while stepping through.
[insert witty comment here]
bdiamond
|
|
|
|
|
Nice suggestion, but you might want to reply to V. so that he is sure to see it.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Never ever compare for equality with true or TRUE . Always do if (labMask.hideemptyrows) . The reason is that, even with a bool variable, there's nothing stopping the variable from getting values other than 0 or 1. When you compare against true , the test will fail if the bool got some value other than 1.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
I just performed the Heimlich Maneuver on SQL #1.
-- Chris Maunder
|
|
|
|
|
Tnx for your reply.
However I do not agree on this one:
1. a BOOL is an "Integer", a bool a "Boolean" (true or false)
so it can't get another value then true or false. Can it?
2. even after casting (bool)labMask.hideemptyrows the if statement returned false (we saw it in the quickwatch window)
3. although I see your point (especially for BOOLs) I find it more readable to compare against true or false (you see instandly what type your variable is)
So idd if the bool class can have other values then true or false I see your point, but why use the bool and not the BOOL? (surely not memory?)
Personally I think the compiler is broken or something
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|