By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Coponent Question for C++ Language Expert

P: n/a
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.Uno UrlResolver" ))
My Question:

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

Why not an implied conversion?

Mar 20 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Mar 20, 1:24 pm, "Reporter" <TruckSaf...@gmail.comwrote:
createInstanceWithContext( OUString::createFromAscii("com.sun.star.bridge.Uno UrlResolver" ))

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.
Mar 20 '07 #2

P: n/a
On Mar 20, 1:24 pm, "Reporter" <TruckSaf...@gmail.comwrote:
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.Uno UrlResolver" ))

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.

Mar 20 '07 #3

P: n/a
Reporter wrote:
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.Uno UrlResolver" ))

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.
Mar 20 '07 #4

P: n/a
Hi

Reporter wrote:
In order to create UNO Component compatable strings in C++ a static
function "OUString::createFromAscii" is used as follows:
[...]
Why not add a constructor to OUString which accepts a char * as a
parameter?
What is the "Named Constructor Idiom"?
http://www.parashift.com/c++-faq-lit....html#faq-10.8

C++ idioms for $400, please...

Markus

Mar 21 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.