|
thanks very much.
It works perfectly.
thanks for ur help.
|
|
|
|
|
Or how about:
unsigned char* byteptr = (unsigned char*)&floatVal;
for(int i = 0; i < sizeof(float); ++i)
Send(byteptr[i]); You can use this technique for any struct/basic type, without having to create a "converter" union for each type.
--
For External Use Only
|
|
|
|
|
I need to use a ccontrol list to show data, after pressing button 'showdata'.....in a old project(DIALOG BASED).....the problem is that..... in this project i can't use class wizard.
kamalesh
|
|
|
|
|
Have you removed the wizard comments from source?
AFAIK we can use class wizard, only if we created the project by classwizard.
When pressing the Ctrl+W it will ask for the list of files. I think it appears only for the projects created through class wizard
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
I set a treeview toolbar in my MDI project.
just like the VC++ 6.0 workspace toolbar,Click the item/filename of the fileview, the related file opens and become active. and insert/delete item of the tree, it will new/close the related doc/file .
1.>how to create a new file for the new item ?
2.>when DbclickTree() happens, how to active the related file?
3.>does the files can searched/sort by filename as the treeview item sort?
thanks for ur kind help!
|
|
|
|
|
Hey Guys,
does anybody know a good implementation of the Sorenson H.263 Codec ? I couldn't find a nice on. Well I found some links but they were dead
I appreciate any help.
Thanks,
Ben
|
|
|
|
|
Hi all,
I created combo box with control variable. I like to set the no of characters to be keyed in in the combobox(editable).
In brief, set the text limit to the Combobox control variable. Can anyone help me in this problem?
Thanks in Advance.
Regards,
Ram
|
|
|
|
|
Follow these steps:
1) From View menu, bring up the MFC ClassWizard
2) Add a member variable of CString type for the ComboBox
3) Set maximum characters to a number of your choice
4) Recompile the project
Best,
Jun
|
|
|
|
|
I already set member variable type CComboBox type to the combobox.
And now i have created one more member variable CString type as u hv specified. still i couldnt able to set the text limit to the combo box. advice on this.
Thanks.
Regards,
Ram
|
|
|
|
|
On the "Member Variable" panel, select the variable you just created. As it's a CString type, an edit box named "Maximum characters" will appear at the bottom.
Best,
Jun
|
|
|
|
|
class RTI_EXPORT RTIambassador {<br />
public:<br />
#include "RTIambServices.hh"<br />
RTIambPrivateData* privateData;<br />
private:<br />
RTIambPrivateRefs* privateRefs;<br />
};<br />
<br />
class RTI_EXPORT FederateAmbassador {<br />
public:<br />
#include "federateAmbServices.hh"<br />
};
WHOAA!! What is this suppose to mean
How come we have two names for this class
class RTI_EXPORT RTIambassador {<br />
<br />
.....<br />
<br />
};
Does this mean you can refer to this class by two different names
|
|
|
|
|
|
i need to know how to get the width of a string of text
.GetLength("string"); will return 6
.GetLength("String"); also returns 6
but
.GetStringWidth("string"); returns 22
.GetStringWidth("String"); returns 27 which is what i need but .GetStringWidth is part of a listctrl and i may not always use a listctrl with my class so i need a work around for it.
i hope this is clear on what i need.
|
|
|
|
|
from the MSDN:
CListCtrl::GetStringWidth : The width, in pixels, of the string pointed to by lpsz.
CString::GetLength: A count of the bytes in the string.
bytes != pixels
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
i know that i need the width in pixels just dont know how to get it.
|
|
|
|
|
in that case, you need to :
1. create a font object that reflects the font you're going to use when you draw the text
2. create a DC
3. select your font into that DC
4. use something like DrawTextEx or CDC::GetTextExtent to measure the text
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
class Derived: public string <br />
{<br />
public:<br />
~ Derived() { --destr;}<br />
};<br />
int main()<br />
{<br />
string * p = new Derived;<br />
delete p;
cout>> destr >>endl;
}
Class Derived publicly inherits from Class String
My question is, is
String *p = new Derived;
same as
String *p;<br />
p = new Derived;
-- modified at 17:38 Tuesday 4th July, 2006
|
|
|
|
|
Deriving from std::string is asking for trouble...
--
Based on a True Story
|
|
|
|
|
what are virual destructors? I'm tryin to understand this file
why do we have a destructor function from a derived class which is empty
class ObjectRoot <br />
{<br />
public:<br />
<br />
virtual ~ObjectRoot<br />
<br />
};<br />
<br />
<br />
<br />
class Ball : public ObjectRoot <br />
{<br />
public :<br />
<br />
virtual ~Ball<br />
};<br />
<br />
ObjectRoot::~ObjectRoot<br />
{<br />
......<br />
......<br />
......<br />
}<br />
<br />
<br />
Ball::~Ball <br />
{<br />
}
CAN ANYONE TELL ME WHAT IS GOING ON HERE PLZ
-- modified at 16:59 Tuesday 4th July, 2006
|
|
|
|
|
The virtual destructor allows the destructor of derived classes to be called when deleting the instance through the base class.
In other words, an instance of Ball can be assigned to an ObjectRoot pointer:
ObjectRoot* pBase = (ObjectRoot*) new Ball;
and then deleted:
delete pBase;
The virtual destructor ensures that Ball's destructor will be called.
Often, destructors do nothing, but the empty virtual implementation is left just in case something later is added.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
class A {
public:
A() { }
~A() { }
};
class B : public A {
public:
B() { }
~B() { }
};
B* b = new B();
delete b;
A* a = new B();
delete a;
When a C++ compiler sees a method call, it first checks to see if the method is virtual or not. If it is not virtual, it will use the object variable's static type information, to determine what method to call. If the variable is of type B* , it will first look in B 's definition, and fallback on A if no matching method could be found.
If the method is virtual, the compiler will generate code which calls the method furthest down in the inheritance tree.
The same idea applies to destructors. If you call delete on b , as above, the compiler will first check if the destructor is virtual in the class hierarchy. In this case, it's not. Therefore it will inspect B 's definition, as the variable is of type B* . It'll find the destructor, and call it. After that, the compiler will generate code which calls all parent classes' destructors. In the case of the variable a , the compiler will, as earlier, see that the destructor is not virtual, and will therefore look into A 's definition for the destructor (a is of type A* ). The compiler will then generate code which calls A::~A() , and nothing more. You can easily understand that this is a problem, if B::B() did stuff like new ... .
Two analogies: virtual destructors are like doubly linked lists; you can always find the end of the list from any node in the list - meaning that the compiler will always call the destructor furthest down the inheritance tree, and then work its way back to the root. Non-virtual destructors are like singly linked lists; you can not find the end of the list from all nodes in the list - meaning that the compiler can't call the destructors which comes "after" the class in question.
The golden rule: virtual methods are virtual, if and only if, the first declaration is declared as virtual.
--
Transmitido en Martian en SAP
|
|
|
|
|
Hey, thanks for the descriptive information on destructors. The only problem is that Im a beginner.
A* a = new B();
how can a Pointer to an A object create a new B object?
its like saying
int *a = new double;
Im definately not right but, I have a hard time thinking how it looks like
Please help me out here.
Thanks,
Jay
|
|
|
|
|
Jay03 wrote: A* a = new B();
how can a Pointer to an A object create a new B object?
its like saying
int *a = new double;
No, not really. A double doesn't inherit from int. With your A and B, the story is different.
When you declareclass B : public A you state a relationship between class A and B. That relationship is "B is an A". This relationship means that wherever you can put an A*, you can put a B*. For instance, suppose you have the function
void function(A* a) { ... } it means that you can do this:
B* b = ...;
function(b); . Why? Because we've stated that B is an A. This is the essence of inheritance. You use these relationships to make your programs more modular and interchangeable.
For example: Suppose you have the class Instrument . It has the virtual method PlayNote(char* note) . Suppose note is a string with a "C", "A", "B#", or any other playable note. The class Guitarr , Flute and Organ all derive from Instrument . Their versions of PlayNote produces the corresponding sound. With this inheritance setup, you can do things like this:
Instrument* instrument = new Guitarr();
instrument->PlayNote("C");
instrument->PlayNote("F");
instrument->PlayNote("G"); This will make each call to PlayNote produce guitarr sounds. Should you ever want to switch to an organ, just do this instead:
Instrument* instrument = new Organ();
instrument->PlayNote("C");
instrument->PlayNote("F");
instrument->PlayNote("G"); One word switched, and the program now behaves very differently (and hopefully sounds a lot more different too!)
Now, using inheritance, you can make your own orchestra. How? Well, check this out:
Instrument* orchestra[3];
orchestra[0] = new Guitarr();
orchestra[1] = new Flute();
orchestra[2] = new Organ();
for(int i = 0; i < 3; ++i) {
instrument->PlayNote("C");
instrument->PlayNote("F");
instrument->PlayNote("G");
} See how easy that was? All we had to do was to declare an array to hold 3 pointers to Instrument . Then we stuffed each entry with an various instruments. The reason we can do this, is that because of the relationship "Guitarr is an Instrument", "Flute is an Instrument", and "Organ is an Instrument".
This is just one tiny portion of what you can do with inheritance. The tricky part is how you express it in the C++ language. You have already faced one learning obstacle in the language: virtual and non-virtual methods and destructors. For this example to work, PlayNote must be a virtual method. Why? Well, had the method not been virtual, and you have calls like this:
Instrument* instrument = new Flute();
instrument->PlayNote("C"); the compiler would have generated a call to the version of PlayNote that is declared in Instrument . For all non-virtual methods (and destructors), the compiler looks at the type of the variable to determine which method to call. In this case, the type of the variable is Instrument* . From that the compiler deduces that the method to be called is Instrument::PlayNote . If you make the method virtual , the compiler won't be so "dumb" about it, and call the correct method (in this case Flute::PlayNote ). Why on earth is the compiler behaving this dumb by default you might ask? The reason is purely technical, although very valid in some scenarios, and certainly was valid back in the days when C++ was designed. When you declare a virtual method, the compiler adds extra data to the object (typically 4 bytes per object in a 32 bit environment), which it uses to determine which method to call. This overhead is unbearable in some scenarios, as internal memory may be a scarce resource.
Note that this "is a"-relationship only holds in one direction. Suppose we have class B : A again. Given this, we cannot write code like
B* b = new A(); . Why? Because the relationship does not say "A is a B". To elaborate on why this is correct, see here:
class A {
public:
virtual void Method() { cout << "A::Method called"; }
};
class B : public A {
public:
virtual void Method2() { cout << "B::Method2 called"; }
};
B* b = new A();
b->Method();
b->Method2(); Generally speaking, whatever you declare in A is also declared in B automatically. That is to say that not only can you call Method2 through B, you can also call Method . The same does not hold for A - whatever's declared in B is not declared in A. With this in mind, what method will be called here: b->Method2() ? The variable b is of type B* . From this, the compiler deduces that there is indeed a method named Method2() available. But.. keep in mind that we didn't create an object of class B , we created one of class A . A doesn't have the method Method2 . Should you try, the C++ compiler catch the error, emit an error message and stop the compilation. (So there's no need to worry about it! )
Without a whiteboard and a lab, my pedagogical skills stretches only this far (although, I hope I made some sense). I advise you to pick up the book C++ Primer (4th Edition)[^] at the bookstore or your local library (any edition will do, as the basics of C++ hasn't changed much over the years). It'll give you a far better foundation that any of us could give you on a web forum. Also, make sure you experiment a lot. If in doubt; write it and test it - that methodology and armed with a good book is the best way to learn in my opinion.
By the way, in C++, it's good manner to put the asterisk adjacent to the type, rather than the variable. Like this: Type* pointer . I could go on as to why that's the norm, but I feel I would be giving you information that you don't need right now. Only old timers (former C programmers) and stubborn people put the asterisk adjacent to the variable name.
--
[LIVE] From Omicron Persei 8
|
|
|
|
|
class Instrucment {
public:
virtual void PlayNote(char* note)
};
Instrument* instrument = new Guitarr();
instrument->PlayNote("C");
instrument->PlayNote("F");
instrument->PlayNote("G");
What if PlateNote(char* note) was not virtual
how would u call it
instrument->Instrument::PlayNote("C") ; //????
-- modified at 20:26 Tuesday 4th July, 2006
|
|
|
|
|
Then you'd have to do something like this:
Guitarr* g = new Guitarr();
Flute* f = new Flute();
Organ* o = new Organ();
f-> PlayNote("C");
f-> PlayNote("F");
f-> PlayNote("G");
g-> PlayNote("C");
g-> PlayNote("F");
g-> PlayNote("G");
o-> PlayNote("C");
o-> PlayNote("F");
o-> PlayNote("G"); Not very flexible, as you can see.
--
Filmed on LocationLast modified: den 4 juli 2006 19:39:38 --
|
|
|
|
|