473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

operator+= question

Hi,

I have the following definition of a pure abstract class:

class lb_I_String {

// ...

virtual lb_I_String* LB_STDCALL operator += (const char* toAppend) =
0;

// ...

};

And use it like this:

lb_I_String* newWhereClause = getStringInstance(); // A fictive
'instance maker' :-)

newWhereClause = " where ";

newWhereClause += "column1 = ";
Why I get these error messages ?
lbDatabaseForm.cpp: In member function `void
lbDatabaseDialog::updateFromMaster()':
lbDatabaseForm.cpp:1904: error: cannot convert `const char[8]' to
`lb_I_String*
' in assignment
lbDatabaseForm.cpp:1906: error: invalid operands of types
`lb_I_String*' and `
const char[11]' to binary `operator+'
lbDatabaseForm.cpp:1906: error: in evaluation of `operator+=(class
lb_I_String*, const char[11])'

Thanks

Lothar

Jul 23 '05 #1
4 1981
* lo************@lollisoft.de:

I have the following definition of a pure abstract class:

class lb_I_String {
I don't understand that name.

Presumably others won't understand it, either.

And it's an open invitation to speling erors.


// ...

virtual lb_I_String* LB_STDCALL operator += (const char* toAppend) =
0;
Should be

virtual lb_I_String& operator+=( char const toAppend[] ) = 0;

// ...

};

And use it like this:

lb_I_String* newWhereClause = getStringInstance(); // A fictive
'instance maker' :-)

newWhereClause = " where ";

newWhereClause += "column1 = ";


This invokes pointer arithmetic, not a user-defined operator.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2
Thanks.

About your comment:

It should be an interface like the ones from M$ COM. Maybe there is a
more usual standard.

E.g. IString for interface of a string.

Ok, this would be a desision, I would make at any time. But not now :-)

Jul 23 '05 #3
Alf P. Steinbach wrote:
* lo************@lollisoft.de:

I have the following definition of a pure abstract class:

class lb_I_String {


I don't understand that name.

Presumably others won't understand it, either.

And it's an open invitation to speling erors.


// ...

virtual lb_I_String* LB_STDCALL operator += (const char* toAppend) =
0;


Should be

virtual lb_I_String& operator+=( char const toAppend[] ) = 0;


I'd not recommend to use [] for pointer parameters. If it's a pointer, just
write it down as one.

// ...

};

And use it like this:

lb_I_String* newWhereClause = getStringInstance(); // A fictive
'instance maker' :-)

newWhereClause = " where ";

newWhereClause += "column1 = ";


This invokes pointer arithmetic, not a user-defined operator.


To elaborate a bit: newWhereClause is a pointer, so the operator= and
operator+= are called for pointers, not for lb_I_String objects. So your
operator defined above won't be used at all.

Jul 23 '05 #4
I really do it a bit different.

Only declare char* as the parameter for the operator. Before, that was
a try.

*newWhereClause = " where ";

*newWhereClause += " column1 = ";

This is a little ugly, but I do not know a work around. My real code
uses smart pointers,
that I have defined. Also defining the operators in the smart pointers,
is not good, I think.

But at least it defines some dereference operators. Then it is this way
(UAP = unknown automatic pointer (handle body pattern I think)):

UAP(lb_I_String, colName)
colName = myMasterFormDefinition->getMasterColumn(i);

*newWhereClause += *&colName; // * = reference, *& = dereferenced
pointer-pointer
bool isChar = myMasterFormDefinition->isCharacterColumn(i);

if (isChar)
*newWhereClause += " = '";
else
*newWhereClause += " = ";

In both situations, a normal pointer or a smart pointer with an
operator* or & must be used. Could I declare these operators in my
smart pointer so that it will be 'forwarded' ?

Thanks

Lothar

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeremy Howard | last post by:
Hello everyone, I'm not a database guru so I'm sorry if this is a dumb question but here it goes... I have this sql query that I'm trying to run against a table on a Sql 2k server: SELECT ...
7
by: John J | last post by:
To write a unary operator- operation that returns the negative of a value is it just as simple as subtracting the value from itself? ie. { return (value - value); } Thanks
9
by: Matthew Polder | last post by:
Hi, When a class Apple is written and the assignment operator is not explicitly declared, the operator Apple& operator=(const Apple&) is created by the compiler. Is there any difference...
2
by: Ook | last post by:
This is a few ways I've seen to overload operator+. I can understand that you would want to pass a reference to the function if you wanted to change some of the data elements of the class, but in...
6
by: Rick | last post by:
Hi again, I once saw that it was possible to define operators in C++ or something so I was thinking, is it possible to store and use operators in C? For example, first I read out a formula char...
11
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal...
1
by: hunter hou | last post by:
Hello,Please look at the following code(from C++ in a nutshell) and my questions.Thanks,***Hunter... typedef void (*strproc)(const char*); void print(const char* str) { std::cout << "const...
2
by: mati-006 | last post by:
Hi Why there is no "counted_ptr& operator= (pointee_type* p)" ? This question has arisen when I was searching why following piece of code won't compile: arg::counted_ptr<testc; c = new test; ...
4
by: raiderdav | last post by:
I understand how the ternary operator (question mark - ?) works in an if/else setting, but what does it mean when used as a type? For instance, I'm trying to add a get/set in some existing code,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.