Coponent Question for C++ Language Expert

R

Reporter

I posted a question related to this on the Open Office Org forum.
Basically the Open Office API interface is defined as a component
interface and its native objects are called UNO objects.

"string" is a fundamental type in UNO.

In order to create UNO Component compatable strings in C++ a static
function "OUString::createFromAscii" is used as follows:



rInstance =rServiceManager-
createInstanceWithContext( OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ))

My Question:

Why not add a constructor to OUString which accepts a char * as a
parameter?

Why not an implied conversion?
 
D

dave_mikesell

My Question:

Why not add a constructor to OUString which accepts a char * as a
parameter?

Why not an implied conversion?

Good questions. Seems like that would have been a more natural way to
do it.
 
A

AnonMail2005

I posted a question related to this on the Open Office Org forum.
Basically the Open Office API interface is defined as a component
interface and its native objects are called UNO objects.

"string" is a fundamental type in UNO.

In order to create UNO Component compatable strings in C++ a static
function "OUString::createFromAscii" is used as follows:

rInstance =rServiceManager-


My Question:

Why not add a constructor to OUString which accepts a char * as a
parameter?

Why not an implied conversion?
Perhaps they didn't want to clutter their class interface with
numerous conversion functions. Perhaps they deal internally
with one way of representing characters and there are numerous
ways of externally representing the same thing.

Placing these external representation in functions which in
effect represent an interface layer removes any knowledge of
the external representations from the core classes.

Just a guess.
 
F

Fei Liu

Reporter said:
I posted a question related to this on the Open Office Org forum.
Basically the Open Office API interface is defined as a component
interface and its native objects are called UNO objects.

"string" is a fundamental type in UNO.

In order to create UNO Component compatable strings in C++ a static
function "OUString::createFromAscii" is used as follows:



rInstance =rServiceManager-

My Question:

Why not add a constructor to OUString which accepts a char * as a
parameter?

Why not an implied conversion?

Because implicit conversion is the root of all evil..just kidding. First
of all, this kind of type conversion operator should usually be declared
as explicit. Did you expect this to work?
class A{
public:
A(){}
A(int x){}
};

int main(){
A y;
y = 3; // y.operator=(const A & A(int));
}

or this is more like what you want?

class A{
public:
A(){}
explicit A(int x){}
};

int main(){
A y;
y = 3; // Error
}

With implicit conversion, compilers will do under-the-hood work for you
to generate compilable code, which may or may not be what you want. It's
all good if it is what you want, but otherwise it opens a can of worms
beneath your nose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top