two methods with the same name 
Author Message
 two methods with the same name

Hey

I have not programmed in C for a long time and got a little bit rusty.
The problem is as follows: I have two methods:

struct STRING * new_string(_int32 size) { ... }
struct STRING * new_string(char * charArray) { ... }

The compiler (MSVC 6.0) says

d:\adtlib\string.h(11) : warning C4028: formal parameter 1 different
from declaration
string.c
d:\adtlib\string.h(11) : warning C4028: formal parameter 1 different
from declaration
d:\adtlib\string.c(5) : warning C4028: formal parameter 1 different from
declaration
d:\adtlib\string.c(8) : error C2084: function 'struct STRING *__cdecl
new_string(char *)' already has a body

Can't I define two methods of the same name but different signatures?
I have check out the FAQ for this group but there was no answer to my
question.

Thanks for help
radcliff



Mon, 04 Apr 2005 01:57:10 GMT  
 two methods with the same name

Quote:
> Hey
> I have not programmed in C for a long time and got a little bit rusty.
> The problem is as follows: I have two methods:

In C, they are called "functions", not "methods".

Quote:
> struct STRING * new_string(_int32 size) { ... }
> struct STRING * new_string(char * charArray) { ... }
> The compiler (MSVC 6.0) says
> d:\adtlib\string.h(11) : warning C4028: formal parameter 1 different
> from declaration
> string.c
> d:\adtlib\string.h(11) : warning C4028: formal parameter 1 different
> from declaration
> d:\adtlib\string.c(5) : warning C4028: formal parameter 1 different from
> declaration
> d:\adtlib\string.c(8) : error C2084: function 'struct STRING *__cdecl
> new_string(char *)' already has a body
> Can't I define two methods of the same name but different signatures?
> I have check out the FAQ for this group but there was no answer to my
> question.

No, you can't define two functions of the same name but different
signatures. You can only define one function with the same name. If you
want C++, you know where to find it.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"We're women. We've got double standards to live up to."
   - Ally McBeal



Mon, 04 Apr 2005 02:19:44 GMT  
 two methods with the same name

Quote:

> struct STRING * new_string(_int32 size) { ... }
> struct STRING * new_string(char * charArray) { ... }
[snip - errors]
> Can't I define two methods of the same name but different signatures?

No, not in the same scope.

        david

--
...the use of keys+commands required a higher level of mental planning
to organise the interaction, which apparently obscures the perception
of the passage of time...
        -- forsyth on Tognazzini's "Tog on Interface"



Mon, 04 Apr 2005 02:26:25 GMT  
 two methods with the same name

Quote:
>I have not programmed in C for a long time and got a little bit rusty.
>The problem is as follows: I have two methods:

>struct STRING * new_string(_int32 size) { ... }
>struct STRING * new_string(char * charArray) { ... }

You seem to confuse C with C++.  C has no methods and no support for
function overloading.  If you need this feature, use C++.

Dan
--
Dan Pop
DESY Zeuthen, RZ group



Mon, 04 Apr 2005 20:03:42 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting the name of a method from within that method

2. Calling two ActiveX Controls properties and methods in one container

3. Is it possible to call a class method if the class name and method name are in a variable ?

4. Is it possible to call a class method if the class name and method name are in a variable ?

5. using two different static library, function name conflit

6. Same Interface name in two TLB

7. Getting Actual Parameter Name for a method

8. named parameters in method calls?

9. how can use same name methods in control

10. Interfaces with the same Method name and parameters.

11. Define methods with same name but different arguments

12. Method name collision in IDL

 

 
Powered by phpBB® Forum Software