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

why it fails

P: n/a
This program fails i.e it is basically an example of overloading and
inheritence . The same program with minor modification is able to run
in java . please update me on the same.

#include <iostream.h>

class Base {
public:
void func() {
cout << "Base :: func(float) " << endl;
}

};
class D : public Base {
public:
int func(int f) {
cout << "D :: func(int) " << endl;
return 0;

}
};
void main() {

D *pobj = new D();
pobj->func( );
}

The Error is
ompiling...
typ.cpp
typ.cpp(29) : error C2660: 'func' : function does not take 0
parameters
Error executing cl.exe.

typ.obj - 1 error(s), 0 warning(s)
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
cpluszaap wrote:
This program fails i.e it is basically an example of overloading and
inheritence . The same program with minor modification is able to run
in java . please update me on the same.

#include <iostream.h>

class Base {
public:
void func() {
cout << "Base :: func(float) " << endl;
}

};
class D : public Base {
public:

using Base::func;

int func(int f) {
cout << "D :: func(int) " << endl;
return 0;

}
};
void main() {

D *pobj = new D();
pobj->func( );
}

Jul 23 '05 #2

P: n/a
Thats fine. But i want it without using USING.

Jul 23 '05 #3

P: n/a
at*****@gmail.com wrote:
Thats fine. But i want it without using USING.


void main() {
D *pobj = new D();
pobj->Base::func( );
}
Jul 23 '05 #4

P: n/a

Gianni Mariani wrote:
at*****@gmail.com wrote:
Thats fine. But i want it without using USING.


void main() {
D *pobj = new D();
pobj->Base::func( );
}


hey where would you put "using" clause.?. sorry i am newbe

Jul 23 '05 #5

P: n/a
" Using " is be put in the begining of derived class .

i.e
class D : public Base {
public:
using Base func;
int func(int f) {
cout << "D :: func(int) " << endl;
return 0;
}

Jul 23 '05 #6

P: n/a

"cpluszaap" <at*****@gmail.com> wrote in message
news:a0**************************@posting.google.c om...
This program fails i.e it is basically an example of overloading and
inheritence . The same program with minor modification is able to run
in java .
C++ is not Java. They're two completely separate, distinct
languages. You cannot assume one will behave like the other,
regardless of any similar syntax.
please update me on the same.

#include <iostream.h>
#include <iostream>
#include <ostream>

using std::cout;
using std::endl;

class Base {
public:
void func() {
cout << "Base :: func(float) " << endl;
Why does your message indicate that this
function takes a 'float' argument? It
takes no arguments at all.
}

};
class D : public Base {
public:
int func(int f) {
cout << "D :: func(int) " << endl;
return 0;

}
};
void main() {
int main()

D *pobj = new D();
pobj->func( );
}

The Error is
ompiling...
typ.cpp
typ.cpp(29) : error C2660: 'func' : function does not take 0
parameters


This is exactly true. You've defined D::func() as taking
one argument of type 'int', but your call doesn't supply
any arguments. Write:

pobj->func(0); /* or whatever value argument you want */

Or perhaps you might explain exactly what you're trying
to do. (If you're trying to achieve polymorphism, note
that it must be done via a pointer (or reference) to
the *base* class.)
-Mike
Jul 23 '05 #7

P: n/a
GTO
Do you want something like:

#include <iostream>

using namespace std;

class base
{
public:
void func()
{
cout << "base::func() " << endl;
}
};
class D : public base
{
public:
int func(int i)
{
cout << "D::func(" << i << ") " << endl;
return 0;
}
};

void main()
{
D *d = new D();
base *b;
b = d;
d->func(5);
b->func();
}

or do you plan to implement polymorphism?

Gregor

"cpluszaap" <at*****@gmail.com> wrote in message
news:a0**************************@posting.google.c om...
This program fails i.e it is basically an example of overloading and
inheritence . The same program with minor modification is able to run
in java . please update me on the same.

#include <iostream.h>

class Base {
public:
void func() {
cout << "Base :: func(float) " << endl;
}

};
class D : public Base {
public:
int func(int f) {
cout << "D :: func(int) " << endl;
return 0;

}
};
void main() {

D *pobj = new D();
pobj->func( );
}

The Error is
ompiling...
typ.cpp
typ.cpp(29) : error C2660: 'func' : function does not take 0
parameters
Error executing cl.exe.

typ.obj - 1 error(s), 0 warning(s)

Jul 23 '05 #8

P: n/a
Gianni Mariani wrote:

void main() {
D *pobj = new D();
pobj->Base::func( );
}


main must have return type 'int'.

Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.