|
In class declaration, it has a constructor:
MyString(const char * istr);
|
|
|
|
|
The implementation of your overload must match the definition, in parameters and return type. You are trying to define the overload as:
friend MyString& operator+(const char* iStr, const MyString& iMyStr);
and the implementation as:
char* operator+(const char* iStr, const MyString& iMyStr)
{
}
The return types are different.
|
|
|
|
|
Please don't do that.
Such a operator should only return a MyString reference.
Veni, vidi, vici.
|
|
|
|
|
but, I use :
return MyString(newStr);
I got a compile error message.
|
|
|
|
|
You have to change the method signature.
It is safe to add a C -like string to a MyString object and then return a reference to the latter:
MyString & operator+(MyString & iMyStr, const char * str);
Veni, vidi, vici.
|
|
|
|
|
I am testing the constructor call with the code below:
#include <iostream>
class A
{
public:
A(int n = 0)
: m_n(n)
{
}
A(const A& a)
: m_n(a.m_n)
{
}
private:
int m_n;
};
int main()
{
A a(2), b(1);
const A c(a);
const A &d = c;
const A e = b;
b = d;
return 0;
}
Everything is OK with me.
But there is one point that I cannot understand is that: At the line "b = d" (Note 2), why the copy constructor is not called while at the line "const A e = b" (Note 2) the constructor is called?
I expect that at line Note 2, the copy constructor will be called to copy the value of "c" (referenced by "d") to "b", but it doesn't happen.
Please explain it, thank you in advance!
|
|
|
|
|
Hi,
You are not invoking the assignment operator with your const A e = b; . You are constructing a new object of const A e and performing initialization by copy of b .
This is covered in section 8.5 paragraph 15 of the latest standard.
www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks Randor for your prompt reply.
As your answer, I can conclude that the copy constructor will be call for initialization only, not for "=" (assignment operator). Since long time ago, I have believed that the copy constructor will be call for "=" operator if there is no "=" operator defined for that class.
But I still wonder this: If there is no "=" operator defined for that class, what will be implemented for "=" operator? Binary copy?
Thanks.
|
|
|
|
|
Hi,
trinh.nguyen wrote: But I still wonder this: If there is no "=" operator defined for that class, what will be implemented for "=" operator? Binary copy?
If you do not write an assignment operator for your class the compiler will generate a default assignment operator that performs a memberwise copy[^] of base classes and members.
Have a look at section 12.8 paragraph 15:
www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hello,
I want to make a USB write blocker with c++ to work for linux. I have been looking for open source USB write blockers, but I just found few for windows that disable the writing functionality from the registry. The idea is to prevent the OS from changing the USB devices timestamps while plugging the device for cloning or analysis the data.
I need help in figure out the best way to do it.
Thank you.
|
|
|
|
|
Override ::
MSVC > Class View > Properties > Override >
OnKillActive , OnSetActive
/*Dialog ( in sheet page ) */
virtual BOOL OnKillActive();
virtual BOOL OnSetActive();
/*exit page*/
BOOL CMyPropertyPage1::OnKillActive()
{
TRACE(_T("OnKillActive\n"));
return CMFCPropertyPage::OnKillActive();
}
/* entrance page*/
BOOL CMyPropertyPage1::OnSetActive()
{
TRACE(_T("OnSetActive\n"));
return CMFCPropertyPage::OnSetActive();
}
Visual C
|
|
|
|
|
Do you have a specific question, or are you just posting random code?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
|
Hi, I am confused with screen/window/client coordinate in windows programming.
As I understand, 3 coordinates are like the following:
screen top left point: spoint(Xs,Ys);
window top left point: wpoint(Xw,Yw);
client top left point: cpoint(Xc,Yc);
so the related position for 3 points are:
spoint -----------
| wpoint----------
| |
| cpoint ----------
|
|
GetWindowRect(&rect) gets wpoint;
ScreenToClient(&rect) gets which point? if it gets cpoint,then
cpoint (x,y) based on wpoint, or spoint?
And in a dialog template:
CONTROL "",IDC_STATIC_TST,"Static",SS_BLACKFRAME,80,83,118,35
80,83,118,35 based on client top left point?
|
|
|
|
|
Hi,
It's all relative, my dear Watson.
econy wrote: ScreenToClient(&rect) gets which point?
ScreenToClient will convert a screet RECT (your 'spoint') coordinates to be relative to client RECT (your 'cpoint'). In your example the top and left will be negative coordinates relative to the client top/left.
Window Coordinate System[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hi
I am new to c++ and I have an assignment to write a program to compute the Average daily solar energy collectable from January 1st to December 31st per square meter (kWh/m^2/day) using a 2-axis tracking collector in Albuquerque, can any one help me with this
|
|
|
|
|
Well... get started and ask specific questions. I think you'll get more fruitful responses that way. Good luck!
|
|
|
|
|
Thanks Albert
I will attached more specific information
|
|
|
|
|
Its very simple, from an IT perspective. Your hardware, whatever it is that measures radiation, plugs into your serial/USB port, your app opens that, and takes readings on a periodic basis, collates them, and averages them.
The problem is how you distinguish solar radiation at the surface from back radiation from GH gasses. (assuming you will be measuring at the surface and not TOA).
|
|
|
|
|
i have a library, which i can not modify. this library is called from a console app, and as part of its processing, this library dumps a large and variable amount of debug/trace info to stdout. i'd like to be able to read what the library is sending to stdout from the calling code, in order to extract certain pieces of info for analysis. basically, i want to capture some of what the library prints during a call, save that info away until the call completes, then re-print the info in a better format. this would help me from having to search the hundreds of lines of output to find the particular bits i need.
(this is Windows, C++)
is such a thing possible?
|
|
|
|
|
|
i need to do this within the calling app, not from the shell.
|
|
|
|
|
Do you need this for trouble-shooting or all the time? ...because it sounded like you just needed for troubleshooting, in which case... why not use the shell options?
..but otherwise, you can always try reassigning the stream using freopen[^].
Here's an actual example...
http://support.microsoft.com/kb/58667[^]
|
|
|
|
|
Albert Holguin wrote: Do you need this for trouble-shooting or all the time
all the time.
|
|
|
|