What would this defintion mean: int Function(class CString filename)

Discussion in 'C++' started by huguogang@gmail.com, Sep 26, 2006.

  1. Guest

    Just curious, any one know what the 3 part parameter "class CString
    filename" would mean.

    The code:
    int TestFunc(class CString filename)
    {
    fopen(filename, "w");
    }

    Compile using Visaul C++, there is no complain about the defintion. But
    the following error:

    error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to
    'const char *'
    Source or target has incomplete type


    I know if I remove "class" in parameter list, the function just compile
    fine. But what would it mean if I keep "class" there?

    Any hint?
    , Sep 26, 2006
    #1
    1. Advertising

  2. Greg Guest

    wrote:
    > Just curious, any one know what the 3 part parameter "class CString
    > filename" would mean.
    >
    > The code:
    > int TestFunc(class CString filename)
    > {
    > fopen(filename, "w");
    > }


    It means that "CString" is the name of a class - the class of the
    "filename" parameter that is passed by value to the implementation of
    the function TestFunc().

    > Compile using Visaul C++, there is no complain about the defintion. But
    > the following error:
    >
    > error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to
    > 'const char *'
    > Source or target has incomplete type
    >
    >
    > I know if I remove "class" in parameter list, the function just compile
    > fine. But what would it mean if I keep "class" there?


    Are you sure that removing the keyword "class" fixes the compiler
    error? It's not impossible, but it would have to mean that "CString" is
    not in fact the name of a class as the parameter declaration claims.
    Instead CString would have to be the name of a typedef.

    Now the error that the compiler reports is it cannot find the
    definition of the class CString. And the compiler must have CString's
    class definition because filename, a CString parameter, is being passed
    by value to TestFunc.

    So the upshot is that either the keyword "class" as it is being used
    here is either being completely unnecessary or it is being entirely
    unhelpful.

    Greg
    Greg, Sep 26, 2006
    #2
    1. Advertising

  3. sods Guest

    写é“:

    > Just curious, any one know what the 3 part parameter "class CString
    > filename" would mean.
    >
    > The code:
    > int TestFunc(class CString filename)
    > {
    > fopen(filename, "w");
    > }
    >
    > Compile using Visaul C++, there is no complain about the defintion. But
    > the following error:
    >
    > error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to
    > 'const char *'
    > Source or target has incomplete type
    >
    >
    > I know if I remove "class" in parameter list, the function just compile
    > fine. But what would it mean if I keep "class" there?
    >
    > Any hint?



    have this kind of function definition?
    I think it's grammar error.

    -sods
    sods, Sep 26, 2006
    #3
  4. Guest

    The code is from an old project I am trying to port to VC7.1. Obviously
    VC6.0 has no problem with the grammer.

    In another similar place. I got a compiler error complaining about
    undefined class CString.

    This probably has something to do with the change of CString from a
    real class definition to a typedef in VC7.1.


    Greg wrote:
    > wrote:
    > > Just curious, any one know what the 3 part parameter "class CString
    > > filename" would mean.
    > >
    > > The code:
    > > int TestFunc(class CString filename)
    > > {
    > > fopen(filename, "w");
    > > }

    >
    > It means that "CString" is the name of a class - the class of the
    > "filename" parameter that is passed by value to the implementation of
    > the function TestFunc().
    >
    > > Compile using Visaul C++, there is no complain about the defintion. But
    > > the following error:
    > >
    > > error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to
    > > 'const char *'
    > > Source or target has incomplete type
    > >
    > >
    > > I know if I remove "class" in parameter list, the function just compile
    > > fine. But what would it mean if I keep "class" there?

    >
    > Are you sure that removing the keyword "class" fixes the compiler
    > error? It's not impossible, but it would have to mean that "CString" is
    > not in fact the name of a class as the parameter declaration claims.
    > Instead CString would have to be the name of a typedef.
    >
    > Now the error that the compiler reports is it cannot find the
    > definition of the class CString. And the compiler must have CString's
    > class definition because filename, a CString parameter, is being passed
    > by value to TestFunc.
    >
    > So the upshot is that either the keyword "class" as it is being used
    > here is either being completely unnecessary or it is being entirely
    > unhelpful.
    >
    > Greg
    , Oct 2, 2006
    #4
  5. Jim Langston Guest

    I think it probably has something to do with the fact that VC 6.0 is
    notorious for not following the current standard. 7.1 much closly follows
    the standard.

    <> wrote in message
    news:...
    > The code is from an old project I am trying to port to VC7.1. Obviously
    > VC6.0 has no problem with the grammer.
    >
    > In another similar place. I got a compiler error complaining about
    > undefined class CString.
    >
    > This probably has something to do with the change of CString from a
    > real class definition to a typedef in VC7.1.
    >
    >
    > Greg wrote:
    >> wrote:
    >> > Just curious, any one know what the 3 part parameter "class CString
    >> > filename" would mean.
    >> >
    >> > The code:
    >> > int TestFunc(class CString filename)
    >> > {
    >> > fopen(filename, "w");
    >> > }

    >>
    >> It means that "CString" is the name of a class - the class of the
    >> "filename" parameter that is passed by value to the implementation of
    >> the function TestFunc().
    >>
    >> > Compile using Visaul C++, there is no complain about the defintion. But
    >> > the following error:
    >> >
    >> > error C2664: 'fopen' : cannot convert parameter 1 from 'CString' to
    >> > 'const char *'
    >> > Source or target has incomplete type
    >> >
    >> >
    >> > I know if I remove "class" in parameter list, the function just compile
    >> > fine. But what would it mean if I keep "class" there?

    >>
    >> Are you sure that removing the keyword "class" fixes the compiler
    >> error? It's not impossible, but it would have to mean that "CString" is
    >> not in fact the name of a class as the parameter declaration claims.
    >> Instead CString would have to be the name of a typedef.
    >>
    >> Now the error that the compiler reports is it cannot find the
    >> definition of the class CString. And the compiler must have CString's
    >> class definition because filename, a CString parameter, is being passed
    >> by value to TestFunc.
    >>
    >> So the upshot is that either the keyword "class" as it is being used
    >> here is either being completely unnecessary or it is being entirely
    >> unhelpful.
    >>
    >> Greg

    >
    Jim Langston, Oct 2, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,206
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,625
    Old Wolf
    Jan 20, 2004
  3. Amit_Basnak
    Replies:
    5
    Views:
    452
    Amit_Basnak
    Dec 28, 2006
  4. Steve Hicks
    Replies:
    2
    Views:
    1,261
  5. TriAdmin
    Replies:
    7
    Views:
    130
Loading...

Share This Page