|
Vaclav_Sal wrote: Does that mean that in VC 6.0 I cannot use "namespace"?
Probably.
Your code, exactly what you posted, compiles in VS 2005.
|
|
|
|
|
you're missing something else. namespaces work fine in VC6.
|
|
|
|
|
Addendum:
I build default MFC doc / view app and
I get same error with or without including either iostream or iostream.h.
To me that indictates that iostream does not define namespace.
Can it be defined somewhere else?
|
|
|
|
|
what do you mean by "define namespace" ?
|
|
|
|
|
If I get a syntax error the compiler does not recognize the "namespace" as valid syntax.
So it has to be defined to be vaild. Does not?
For example "if" is defined in similar way, but compiler flags "iff" as undeclared identifier.
I am just trying to find some reason why I am getting same syntax error with or without including iostream.
|
|
|
|
|
'namespace' and 'if' are C++ keywords. they're not defined in headers anywhere, they're built into the compiler itself.
|
|
|
|
|
You've probably left a semicolon, closing brace, closing parentheses or similar off the previous thing in the .h file.
Just out of interest, if you ever want to know if you can use a feature in a compiler just lop the code out and stick it in a .cpp file somewhere, making sure it's not dependent on any other code. In this case had you stuck:
namespace Test
{
int a;
int b;
} in a source file you'd have seen it compiles just fine in VC++6.0. As far as anything can be regarded as "compiling just fine" on that clunky piece of old rubbish.
|
|
|
|
|
Hello Ash,
here is a snippet of VC 6.0 generated CView header file with my add and resulting compliler errors:
class CTESTView : public CView
{
protected: // create from serialization only
CTESTView();
DECLARE_DYNCREATE(CTESTView)
// Attributes
public:
CTESTDoc* GetDocument();
using namespace test
{
int a;
int b;
}
// Operations
public:
.........
This is how iostram is included in STdAfx.h file:
#if !defined(AFX_STDAFX_H__D78D5AFB_F290_4B69_9F5A_23EC3FA245D9__INCLUDED_)
#define AFX_STDAFX_H__D78D5AFB_F290_4B69_9F5A_23EC3FA245D9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <iostream> <b>silly but the CodeProject edit box did not copy stuff in "arrow brackets" - but it is here - iostream
It did not show up in preview, go figure.
</b>
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
.....
And here is the full compiler output regardless of inclusion of iostream or not:
--------------------Configuration: TEST - Win32 Debug--------------------
Compiling...
TEST.cpp
z:\0\0 mdi\test\bamesapce\test\testview.h(23) : error C2059: syntax error : 'namespace'
z:\0\0 mdi\test\bamesapce\test\testview.h(24) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
TESTView.cpp
z:\0\0 mdi\test\bamesapce\test\testview.h(23) : error C2059: syntax error : 'namespace'
z:\0\0 mdi\test\bamesapce\test\testview.h(24) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
Generating Code...
Error executing cl.exe.
TEST.exe - 4 error(s), 0 warning(s)
I am ready to stop trying this, I really do not need it, but the stuff I am modyfying is using it. After succes of using
pure virtual class / function ( BTW many thanks for all you input on that ) I am just "looking for punishment".
Is it possible that I have some kinda of conflict with std namespace?
|
|
|
|
|
using namespace test
{
int a;
int b;
}
that's the problem.
it should be:
namespace test
{
int a;
int b;
};
and then, in your .cpp:
using namespace test; <--- fixed
|
|
|
|
|
Thanks Chris,
and this is the compiler output after your suggestion:
TEST.cpp
z:\0\0 mdi\test\bamesapce\test\testview.h(23) : error C2059: syntax error : 'namespace'
z:\0\0 mdi\test\bamesapce\test\testview.h(24) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
TESTDoc.cpp
TESTView.cpp
z:\0\0 mdi\test\bamesapce\test\testview.h(23) : error C2059: syntax error : 'namespace'
z:\0\0 mdi\test\bamesapce\test\testview.h(24) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
Z:\0\0 MDI\TEST\BAMESAPCE\TEST\TESTView.cpp(60) : error C2873: 'test' : symbol cannot be used in a using-declaration
Generating Code...
Error executing cl.exe.
TEST.exe - 5 error(s), 0 warning(s)
And here is what my ancient MSDN say about namespace:
namespace Declaration
C++ Specific —>
namespace [identifier] { namespace-body }
A namespace declaration identifies and assigns a name to a declarative region.
The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.
The declarative region of a namespace declaration is its namespace-body.
END C++ Specific
Notice - no semicolon.
And if it is a keyword it must not be in my VC6.0 Sp6 stuff.
I give up.
|
|
|
|
|
here is the complete source of a test program demonstrating the use of namespaces in VC6:
namespace foo
{
class testing
{
public:
testing()
{
i = 10;
}
int i;
};
};
using namespace foo;
int main(int argc, char* argv[])
{
testing t();
return 0;
}
|
|
|
|
|
Hi Chris - your line:
testing t(); doesn't actually create a new object. It's a prototype for a function that takes no parameters and returns a testing object.
It's a real bugger with C++ and bites loads of people. It's also the reason that the latest C++ standard introduced uniform initialisation (using braces where we've used parenthesis up to now).
|
|
|
|
|
ok. but that's not the point here.
|
|
|
|
|
Ah ha! Your problem is nesting a namespace within a class. You can't do that. This code gives the same error you got:
class A
{
namespace B
{
}
}; If you want something similar to a namespace nested within a class use another class:
class A
{
class B
{
};
}; It's probably got the effect you want.
|
|
|
|
|
Ash,
you are "the man"! ( Or a woman, I cannot tell from your name)
What has happended, as many times before,lazy me blindly copied ton of #define(s) wiht my new class and there was "use namespace std" in the mess.
I broke my code and had to go back a bit and without the additional defines the namespace stoped giving me syntax error.
One down, thanks to all of you guys persistence.
Appreciate that very much.
Now if I can find someone who knows capAVI and its use in OpenCV I'll be a happy camper.
Thanks Vaclav
|
|
|
|
|
Hi,
I am looking for the best approach to process KeyStroked <ENTER> <F7> <F8>
My code is MFC using Message using message mapping macros
I have a number of questions
1) what would the message be for a Keystrokes
2) is the message directed to the Dialog Box that contains the rich edit or is better to have the rich edit process to message
3) if I wrap the CDialog with a CWinThread
I can use the ::Run command to process the key strokes
<pre lang='cpp'> int CWinthread::Run()
{ ASSERT_VALID(this);
MSG m_msgCur;
for tracking the idle time state
if (!flags.is_connected)
return TRUE;
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{ phase1: // check to see if we can do idle work
while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{ // call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
} // phase2: pump messages while available
do { // pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
// reset "no idle" state after pumping "normal" message
if (IsIdleMessage(&m_msgCur)) {
bIdle = TRUE;
lIdleCount = 0;}
} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}
ASSERT(FALSE); // not reachable
} </pre>
thanks for youe help
|
|
|
|
|
The messages for keystrokes are WM_KEYDOWN and WM_KEYUP .
These are directed to the parent dialog containing the control.
To have the message directed to the control in MFC, you have to create a class derived from CRichEditCtrl and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem[^] method.
|
|
|
|
|
Superman:
I respectfully disagree.
quote: "The messages for keystrokes are WM_KEYDOWN and WM_KEYUP
These are directed to the parent dialog containing the control."
Unless dialog does not contain any controls, dialog window never gets focus, hence WN_KEYDOWN and WM_KEYUP messages are not sent to a dialog.
quote: "and then subclass the control from the InitDialog function of the dialog class using the SubclassDlgItem method."
It is possible to use SubclassDlgItem or SubclassWindow but it would be much easier to let the wizard do subclassing, by simply add variable of the CRichEditCtrl and later replace it with the derived class type.
ForNow:
Depending what is exactly you are trying to achieve, I think the best way to handle special keys is creating accelerators and add handlers to a CRichEditCtrl derived class.
JohnCz
|
|
|
|
|
how about using virtual ::PretranslateMessage
|
|
|
|
|
Hi...
I am working on image quality metrics and i have found that edge stability measure can be used to evaluate different edge detectors according to a paper "statistical evaluation of image quality measures". I am finding it difficult to implement this metric. So can anyone help me or suggest ideas to implement it.
Regards,
Mamatha E
|
|
|
|
|
Hello Friends
OnMouseMove ,After drawing some color stripes,I am using SetCursorPos(x,y) to Set MousePosition manually at end of stripe.
But As I move Only once after that mouse keeps on moving by itself until I dont release mouse lbutton up.
I am assuming that setCursorPos is calling MouseMove so it is going in Infinite Loop.
But,In actual I want to stop mouse pos at end of stripe while mouseMove.
Here is the Flow :
1.)LButtonDown
2.)MouseMove(drawing stripe then setCursorPos() calling) [want mouse cursor at end of stripe]
And again if Mousemove,strip should draw and cursor at end of Stripe.
3.)LbuttonUp[releasing the mouse]
Any Ideas??
Regards
Yogesh
modified 24-May-12 8:41am.
|
|
|
|
|
Just remember in a "global" variable that you have done the movement so that you can then ignore OnMouseOver the next time.
|
|
|
|
|
If you're drawing in MouseMove , why do you need to call SetCursorPos .
Please post some relevant code so that we can understand the problem better.
|
|
|
|
|
Hello
As I told that OnMouseMove I am drawin gsome color stripes on Ruler Scale .
Suppose scale is from 1 to 10 and If i am clicked on 2 and moved a little then it draws stripe of 5inch width.after that i want cursor should come at 7th Inch. So,for that i used SetCursorpos to move mouse manually after end of drawn stripe.
Any IDeas ?
Regards
Yogesh
|
|
|
|
|
The question is not clear to me, but let me answer with what I think the question is.
An OnMouseMove handler is called when the mouse is moved over a window.
When SetCursorPos is called, it does not normally call OnMouseMove .
But if the new cursor position as a result of calling SetCursorPos is over the window for which the OnMouseMove handler is created, then it will be invoked.
If that is the case, you will need to set a flag before calling SetCursorPos and then check this flag inside OnMouseMove to distinguish between manually moving the mouse and calling SetCursorPos .
Remember to reset this flag inside OnMouseMove .
|
|
|
|