|
|
The following code gives error. Is there any explanation?
The issue is Child class is not able to use Parent class functions.
Using g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-10)
--------------------------------
#include<iostream>
#include<string>
using namespace std;
class Parent {
public:
Parent(){}
virtual ~Parent(){}
virtual void Run()=0;
protected:
virtual void Form(string abc)=0;
protected:
virtual void Form(string abc, int i)
{
cout<<"ParentForm1 abc:"<<i<<endl;
}
};
class Child:public Parent{
public:
Child():Parent(){}
virtual ~Child(){}
virtual void Run()
{
cout<<"Child run "<<endl;
Form("ABC",1,4);
Form("DEF");
}
protected:
virtual void Form(string abc, string def)
{
cout<<"ChildForm 1 abc:"<<abc<<" Def:"<<def<<endl;
Form(def);
}
virtual void Form(string abc,int i , int b)
{
cout<<"ChildForm2 abc:"<<i<<b<<endl;
Form(abc,i);
}
virtual void Form(string abc)
{
cout<<"ChildForm3 Overridden abc:"<<endl;
}
virtual void TestForm(){
string abc("abababa");
int i=5;
//Parent::Form(abc,i);// This works
Form(abc,i);
}
};
main()
{
Child child;
child.Run();
}
---------------------------------------
$ g++ test_inherit.cpp
test_inherit.cpp: In member function `virtual void Child::Form(std::string, int, int)':
test_inherit.cpp:38: error: invalid conversion from `int' to `const char*'
test_inherit.cpp:38: error: initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
test_inherit.cpp: In member function `virtual void Child::TestForm()':
test_inherit.cpp:48: error: invalid conversion from `int' to `const char*'
test_inherit.cpp:48: error: initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
|
|
|
|
There is a
virtual void Form(string abc, int i);
in class Parent.
and you want to invoke the method in
virtual void Form(string abc,int i , int b);
virtual void TestForm();
in class Child.
it is a mistake.
In class Child, you give two new methods
virtual void Form(string abc, string def);
virtual void Form(string abc,int i , int b);
and override two methods of Parent
virtual void Form(string abc,int i , int b);
virtual void Form(string abc);
They hides the name Form of Parent in class Child, if you want to invoke the method in class Child, you must specify the class name. like this.
Parent::Form(abc,i);
|
|
|
|
|
|
|
|
Thanks for the reply. But as the arguments are different here, should not the C++ compiler resolved it by using name mangling ?
ahjo_nora
|
|
|
|
>>should not the C++ compiler resolved it by using name mangling ?
You mean that overloading?
First, you overrided the method -Form in class Child, it hides the Form in class Parent. So, there are just two method -
virtual void Form(string abc, string def);
virtual void Form(string abc,int i , int b);
to be candidated if you invoke the method Form in class Child.
No virtual void Form(string abc) to be candidated, because you have already hidden it.
|
|
|
|
Thanks jinhao for your input. So what I understand from the discussion is that:
if I override any of the function from the Parent in child, none of the other functions will be available in Child. Is it C++ standard rule?
Here Parent functions:
Form(string)=0;
Form(string, int);
Child Functions:
Form(string) // This has to be defined for parent pure virtual function
Form(string, string)
Form(string,int,int)
//Form(string,int) is not overloaded and I assumed that this is available
// in Child.
So the only way to invoke Form(string,int) in Child is to be specific, like Parent::Form(string, int).
Thanks for your thoughtful discussion.
ahjo
|
|
|
|
Yes, it is a standard C++ rule.
Giving a same name with a virtual function of the base class in a child class, this is called overriding. Overriding will hide the name of the base class.
Giving a same name with an existing function and different signature in a same scope, this is called overloading.
E.g.
class B
{
public:
void foo(){}
};
class A: public B
{
public:
void foo(int) //Hides the B::foo
{
foo(); //What is foo?
}
};
foo in class A is not a overloading function, because the 2 functions is not defined in a same scope. So, A::foo hides the B::foo.
Continue.
class B
{
public:
void foo(){}
};
class A: public B
{
public:
using B::foo; //using-declaration
void foo(int) //Hides the B::foo
{
foo(); //What is foo?
}
};
using-declaration can introduce a name into current scope, if current scope has not a such name, name mangling will use the name which is declared by using-declaration.
Now, class A has not defined a void foo(), and foo(int) can invoke the foo() successfully, and it refers to B::foo;
Name hidding is so normal, like this.
int i;
int main()
{
int i;
i = 5; //Which i?
}
Which i? Obviously, the i defined in main. It hides the i in global scope.
|
|
|
|
Thanks a lot Jinhao for the answer.
ahjo_nora
|
|
|
|
2.1 Please describe the proposed Specification:
The JavaTM Speech API allows developers to incorporate speech technology into user interfaces for their Java programming language applets and applications. This API specifies a cross-platform interface to support command and control recognizers and speech synthesizers, with considerations for future incorporation of dictation and other features.
Version 2.0 will extend Sun's s pre-JCP work on JSAPI 1.0. The new API will stress compatibility with the existing API and the emerging W3C Speech Interface Framework whenever possible.
2.2 What is the target Java platform? (i.e., desktop, server, personal, embedded, card, etc.) bad credit loans
We will target the embedded (J2ME) platform first and consider additional functionality on J2SE and J2EE platforms. Target platforms should have access to sound resources and adequate computing resources.
2.3 What need of the Java community will be addressed by the proposed specification? debt
Applications, especially on Java embedded platforms (such as communications devices, set-tops, telematics, etc.), will require speech as part of their preferred profile. A modern and scalable speech interface will allow these applications to perform various speech related functions from multiple vendors, including speech recognition and text-to-speech, while maintaining portability.
2.4 Why isn't this need met by existing specifications?
While JSAPI 1.0 is a great start, there are still some issues to be resolved. Candidate targets for JSAPI 2.0 include:
*
A service provider interface (SPI) will act as middleware between the JSAPI Layer and the vendor-provided speech engine. This may be based on existing standards such as the SAPI 5.0 service provider API. property
*
The JSGF and JSML specs must track the W3C Voice Browser group's grammar format and synthesis markup languages.
*
Built in support for redirection of audio.
*
Various threading issues (e.g., synchronization via event queues) and reentrancy issues require tighter specification.
* A modular architecture that supports a very small minimum configuration and future growth for the resources of a variety of platforms (e.g., desktop, server).
* Various other specification details require clarification.
* Future consideration for compatibility with telephony APIs (e.g., JTAPI or JAIN).
2.5 Please give a short description of the underlying technology or technologies:
JSAPI does not provide any speech functionality itself, but through a set of APIs and event interfaces, access to speech functionality provided by supporting speech vendors is accessible to the application.
A related service provider interface (JSAPI SPI), a speech engine abstraction layer the sits between JSAPI and the vendor
2.6 Is there a proposed package name for the API Specification? (i.e., javapi.something, org.something, etc.)
javax.speech.*, and possibly javax.speech.embedded, and later javax.speech.desktop, and javax.speech.server. An alternative is a component-based package approach. Component examples include dynamic grammars, spelling to pronunciation modules, etc.
2.7 Does the proposed specification have any dependencies on specific operating systems, CPUs, or I/O devices that you know of?
The device must have local or remote access to sound resources, adequate computing resources, and the need for speech services.
A vendor must also support a JSAPI-SPI-compliant speech engine for the platform.
2.8 Are there any security issues that cannot be addressed by the current security model? stocks
Recording and transmission of audio could become a privacy issue in some applications.
2.9 Are there any internationalization or localization issues?
The API must support multiple languages. Applications must specify localized speech-related resources.
JSAPI will support the selection of speech recognizers based upon the java.util.Locale's they support. The grammar specification will extend JSAPI 1.0's JSGF format, which supports Unicode descriptions of grammars for multiple locales. JSAPI will also support the selection of speech synthesizers based upon the java.util.Locale's they support. The speech synthesis markup specification will extend JSAPI 1.0's JSML format, which supports Unicode descriptions, as an XML application, of synthesis markup documents for multiple locales.
Both the grammar and speech synthesis specifications will track the specifications being done by the W3C voice browser working group (http://www.w3c.org/voice), which are based upon JSGF and JSML. The ability to provide multilingual grammar formats (i.e., a single grammar file that contains multiple languages) and multilingual synthesis markup formats (i.e., a single synthesis document that contains multiple languages) is TBD.
2.10 Are there any existing specifications that might be rendered obsolete, deprecated, or in need of revision as a result of this work?
The status of the current Javax.speech.* can be discussed as part of the process. This effort will strive for backwards compatibility with the existing specification. Additional subpackages will support new functionality (e.g., javax.speech.embedded).
2.11 Please describe the anticipated schedule for the development of this specification.
Approximate one-year delivery of final specification and reference implementation of core JSAPI 2.0. (Several drafts provided earlier for feedback.) SPI-layer for various platform types may be independently scheduled.
|
|
|
|
CSS padding can then be used to give the same presentation of other cellspacing values. This compromise in allowing one thing presentational in his HTML allowed Dan to write robust pages and enables all real control in the CSS term life insurance. I've used this so much that I just think of a table tag name starting with an indivisible string of 21 characters.
For the troublesome non-bubbling events, we can do the same thing Dan did. If a developer is using jQuery, the jQuery.ready() was written so it can be run multiple times and this is all bundled up with event delegation for bubbling events and Brandon Aaron's plugin for the non-bubbling events we can write pages like this
<script type="text/javascript">
$('input[type="text"]').livequery('focus', function() {
alert('a text input has been focused');
});
</script>
stock market
</head>
<body>
<input type="text" focus="jQuery.ready(event)" blur="jQuery.ready(event)">
Now the text input is never left exposed. I probably wouldn't ever need the blur attribute above and I probably would only include the focus attribute in cases where I know I will be attaching focus handlers to an element. One way to think of this is it forces the bubble that otherwise wouldn't happen. We can attach as many focus handlers as we want and the roll your own event handling system can take appropriate action. As a practical backup, in case you are worried that one of these attributes may be forgotton and hence leave the element exposed indefinitely, an optional bottom script, DOM polling, the Edwards solution and the actual window.onload event could call jQuery.ready(). investment property
Because of Brandon's post I've been thinking in terms of jQuery. Instead of jQuery.ready(event) you could create a function called bubble(event) or whatever you like.
The bottom script, DOM polling and Dean Edwards solutions trade a (potentially long) period of broken UI functionality for the ability to program in the unobtrusive style. To me that weights a programmer's stylistic desires too much compared with a properly working UI.
My suggested solution trades a minor impurity in programmer ideals for an always functional UI. It's an "if you can't beat them, join them" solution. It's a compromise but like Dan Cederholm's compromise it is fixed string of attributes that is tacked on without any thought. It may be a challenge to build an efficient implementation of this solution but there is no hacking based on brittle browser features and no exposure. This solution depends only on documented browser features and behavior. That's a compromise I can abide. debt help
|
|
|
|
|
|
|
|