|
plz help me with this code...
<br />
int a = 0;<br />
int p = 2;<br />
int q = 3; <br />
<br />
a += p ? q : 0;<br />
what does the last line mean?
i need to describe it into normal if-then-else form...
thanks all...
From Indonesia with love..!!
|
|
|
|
|
the form p ? q : 0 is
expr1 ? expr2 : expr3
means evaluate expr1. If it is not zero, the value of the whole thing is expr2; otherwise the value is expr3.
so, substituting 0 += 2 ? 3 : 0
since 2 ! = 0
0 += 3
a = 3
...
'g'
|
|
|
|
|
The code maybe translated into (see documentation [^]):
if ( p != 0 )
{
a = a + q;
}
BTW you really need a good C/C++ tutorial.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yaa...
you may be right...
thank to you guys for the help...
From Indonesia with love..!!
|
|
|
|
|
Hi,
i am using CListCtrl in Icon-mode. I am setting the item positions manually with ListView_SetItemPosition32().
I am having a strange bug, y-positions between 0xf000 and 0xffff are not set properly !
Is this a known bug or am i doing something wrong ?
|
|
|
|
|
Could you please post the relevant code?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The code is pretty easy, i did this inside my CListCtrl class:
...
ListView_SetItemPosition32(this->m_hWnd, 0, 0, 0xf100);
POINT p;
GetItemPosition(0, &p);
...
and you will see that p doesn't contain the values i set before!
|
|
|
|
|
Did you use of debugger?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Debugger doesn't help much, because the item-position is sent via SendMessage to ListCtrl.
So its something going wrong inside windows api and not a fault of mfc.
|
|
|
|
|
This simple code fails and there is no extended error message.
The BITMAP data is there and correct.
CBitmap *bmp = new CBitmap();
if(!bmp->CreateBitmapIndirect((BITMAP * ) m_Doc->m_lpBi))
{
.....
PS Ignore -> it is "->" in original!!!
Any constructive suggestion on how to debug this is appreciated.
Thanks for reading.
Cheers Vaclav
|
|
|
|
|
Did you install the CRT and MFC source code? If so, you can step into the MFC implementation code (so long as you're working with a Debug build) and find what Win32 call is failing. That might give you some more information.
Only thing I can think of, apart maybe from finding some sample code, to see if there's anything you're missing?
|
|
|
|
|
This fails in otherwise working MFC document / view program.
And no I cannot step into the API.
Thanks
|
|
|
|
|
May be GetLastError() can give you some hints. Just add @err,hr to the watch window to get the last error description.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Vaclav_Sal wrote: if(!bmp->CreateBitmapIndirect((BITMAP * ) m_Doc->m_lpBi))
I'm suspicious about that cast - why did you need to cast to a BITMAP*?
Based on the limited info, I have a feeling you're not passing the correct structure...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
As always, you are correct!
BITMAP and BITMAPINFO are definitely different!
Here is my wrong code
if(!m_lpBmpInfo)
{
m_lpBmpInfo = (BITMAPINFO *)( new char[m_vfs]);
((LPBITMAPINFOHEADER)m_lpBmpInfo)-&gt;biSize = sizeof BITMAPINFOHEADER;
}
VERIFY(m_lpBmpInfo);
// document bitmap header pointer initialization - do only once in the class
if(!pDocument-&gt;m_lpBi)
{
pDocument-&gt;m_lpBi = (BITMAP *)( new char[m_vfs]);
((LPBITMAPINFOHEADER)pDocument-&gt;m_lpBi)-&gt;biSize = sizeof BITMAPINFOHEADER;
}
VERIFY(pDocument-&gt;m_lpBi);
As always - the de-reference symbol is shown as -&gt; should be "->"
Now I need to figure out what data is missing from BITMAP. Should be easy.
Thanks Mark
Have a great holidays.
Vaclav
|
|
|
|
|
If you need a HBITMAP from a BITMAPINFO or BITMAPINFOHEADER, you may
want to look into CreateDIBitmap() or CreateDIBSection().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a simple base class that holds id's for use in sorting other classes. It is a non-templated class in an single hpp file ( indexedObject, see below )
class indexedObject
{
public:
indexedObject() : _mID(BAD_DB_ID) {}
indexedObject(dbID id) : _mID(id) {}
~indexedObject();
dbID getID(void);
void setID(dbID id);
bool operator<(const dbID& param) const;
bool operator>(const dbID& param) const;
bool operator==(const dbID& param) const;
bool operator!=(const dbID& param) const;
protected:
dbID _mID;
}; // indexedObject
inline indexedObject::~indexedObject() { _mID = BAD_DB_ID; }
inline dbID indexedObject::getID(void) { return _mID; }
inline void indexedObject::setID(dbID id) { _mID = id; }
inline bool indexedObject::operator<(const dbID& param) const
{
return (_mID < param);
}
inline bool indexedObject::operator>(const dbID& param) const
{
return (_mID > param);
}
inline bool indexedObject::operator==(const dbID& param) const
{
return (_mID == param);
}
inline bool indexedObject::operator!=(const dbID& param) const
{
return (_mID != param);
}
I have a templated class that inherits from the base class.
template <class _Ty> class fwdCurve : public indexedObject, public broadCaster
{
blah blah...
}
When I try to define setID in the derived class
template<class _Ty> void fwdCurve<_Ty>::setID(dbID id)
I get a C2244: indexedObject::setID : unable to match function definition to an existing declaration
I am able to work around this by declaring setID() in the derived class definition and explicitly calling the base class method but why is this happening?
I have VS 2005 with SP1 and hotfix KB930859 installed.
|
|
|
|
|
mjackson11 wrote: When I try to define setID in the derived class
template<class _ty=""> void fwdCurve<_Ty>::setID(dbID id)
I get a C2244: indexedObject::setID : unable to match function definition to an existing declaration
Yes - this is the way C++ works...you need a method declaration in the class before you can define it. The declaration in the base class does not change this.
mjackson11 wrote: I am able to work around this by declaring setID() in the derived class definition and explicitly calling the base class method but why is this happening?
If you just want to call the base classes implementation, then you need no method definition or declaration in the derived class.
What are you actually trying to accomplish?
|
|
|
|
|
Sorry, to be more specific, I tried to implement setID() in the derived class without putting setID in the class declaration. That's when it threw the error. If I define setID in the derived class declaration, when I implement it, it does not call the base class setID method. Seems like the compiler is defining them as two different methods instead of the derived class inhereting.
|
|
|
|
|
mjackson11 wrote: If I define setID in the derived class declaration, when I implement it, it does not call the base class setID method. Seems like the compiler is defining them as two different methods instead of the derived class inhereting.
Yep, that's the way most (if not all) OO languages work. The point is that if you do want to call the base classes method, you can very easily. However, if the language automatically called the base classes methods and you didn't want that to happen, you're stuffed.
Anyway - in conclusion, what you've described is the way C++ is meant to work.
|
|
|
|
|
I wasn't entirely clear about the one case when base class methods are called automatically.
If a base class implements a method and your derived class doesn't declare or define it, then the base class method is automatically called.
Consider this code:
#include <iostream>
class Base
{
public:
void A() { std::cout << "Base::A\n"; }
void B() { std::cout << "Base::A\n"; }
virtual void C() { std::cout << "Base::C\n"; }
};
class Derived : public Base
{
public:
void A() { std::cout << "Derived::A\n"; }
virtual void C() { std::cout << "Derived::C\n"; }
};
void VirtualTest(Base* pBase, const char* objName)
{
std::cout << "Calling pBase->A() with pBase = " << objName << "...\n";
pBase->A();
std::cout << "Calling pBase->C() with pBase = " << objName << "...\n";
pBase->C();
}
int main(int, char**)
{
Base base;
Derived derived;
std::cout << "Calling base.A()...\n";
base.A();
std::cout << "Calling base.B()...\n";
base.B();
VirtualTest(&base, "&base");
std::cout << "Calling derived.A()...\n";
derived.A();
std::cout << "Calling derived.B()...\n";
derived.B();
VirtualTest(&derived, "&derived");
}
You should get this output:
Calling base.A()...
Base::A
Calling base.B()...
Base::A
Calling pBase->A() with pBase = &base...
Base::A
Calling pBase->C() with pBase = &base...
Base::C
Calling derived.A()...
Derived::A
Calling derived.B()...
Base::A
Calling pBase->A() with pBase = &derived...
Base::A
Calling pBase->C() with pBase = &derived...
Derived::C
So - Derived overrides the A() and C() from Base and inherits B() from Base . The difference between overriding virtual and non-virtual methods is demonstrated in VirtualTest - when you have a pointer to base , Base::A() gets called because A() is non-virtual, whereas the implementation of C() that is called depends on the actual type of the object that is pointed to, not the type of the pointer.
|
|
|
|
|
My error, I got myself confused. Everything is working correctly. I had gotten confused with constructors that call the base class constructor. I re-declared everything and explicitly called the base class method.
|
|
|
|
|
In addition to Stuart's replies...
You haven't used "virtual' anywhere, so a method implementation in a derived
class has nothing to do with a base class' method.
Even if you use "virtual", you'd still need to include botht the definition and the
implementation in the derived class, and call the base class method explicitly if desired.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello all
I have the following two lines of code to play an avi file:
mciSendString("open Res\\test.avi type avivideo alias myfile", NULL, 0, NULL);
mciSendString("play myfile", NULL, 0, NULL);
The problem is that it plays the audio but no video is displayed.
I can play the video fine in any media player, but it wont show up in the program, but I know its getting to the file because I can hear the audio.
Any suggestions as to what the problem could be?
Thanks.
Chris
|
|
|
|
|
I believe it might have something to do with not having a "window" to play the video in. It might be simpler to use the MCIWnd functions (I've used them and had no problem in playing videos) compared to sending command strings yourself.
|
|
|
|