Illegal call of non-static member function (error)? 
Author Message
 Illegal call of non-static member function (error)?

I receive the Subject error message when I invoke a non-static member
function from a function in my main .cpp file. None of my functions have
been declared as static.

format of source code is:

class CLineData
{
public:

 enum eLineType
  {
...
  Timestamp,
...
   Welcome
  };

  SetLineType(CLineData LineData, eLineType LineType);

....

Quote:
};

main
{
....
func1 (parma);
....

Quote:
};

func1 (parm)
{
    CLineData LineData;
....
     CLineData::SetLineType(LineData, CLineData::Timestamp);
....

Quote:
};

-----
The Internet is a library the size of the world.


Thu, 29 Aug 2002 03:00:00 GMT  
 Illegal call of non-static member function (error)?
Hello!

In C++, you have classes and objects. When you create a class - in this case
CLineData and declare a function within it, you can only use that function
when it is being called from an object of that class.

CLineData LineData;
LineData.SetLineType(...);

If you wish to call functions like Class::Function -
CLineData::SetLineType - then you have to declare them as static. What I
would do in your case is:

class CLineData

Quote:
> {
> public:

>  enum eLineType
>   {
> ...
>   static Timestamp,
> ...
>    Welcome
>   };

>   SetLineType(eLineType LineType);

> ....
> };

> main
> {
> ....
> func1 (parma);
> ....
> };

> func1 (parm)
> {
>     CLineData LineData;
> ....
>      LineData.SetLineType(CLineData::Timestamp)
> ....
> };

What you do is, in your SetLineType instead of passing the CLineData object
as an argument, use the invisible this object(which representes the calling
object). Then, make the TimeStamp declaration static, so you can call it
directly.

Josh



- Show quoted text -

Quote:
> I receive the Subject error message when I invoke a non-static member
> function from a function in my main .cpp file. None of my functions have
> been declared as static.

> format of source code is:

> class CLineData
> {
> public:

>  enum eLineType
>   {
> ...
>   Timestamp,
> ...
>    Welcome
>   };

>   SetLineType(CLineData LineData, eLineType LineType);

> ....
> };

> main
> {
> ....
> func1 (parma);
> ....
> };

> func1 (parm)
> {
>     CLineData LineData;
> ....
>      CLineData::SetLineType(LineData, CLineData::Timestamp);
> ....
> };

> -----
> The Internet is a library the size of the world.



Thu, 29 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error C2352 - illegal call of non-static member function

2. Compiler Error C2352: illegal call of non-static member function

3. illegal call of non-static member function

4. illegal call of non-static member function

5. illegal call of non-static member function *HELP*

6. illegal call of non-static member function

7. illegal call of non-static member function

8. illegal call of non-static member function

9. iilegal call of non-static member function

10. One Problem in Calling Static function from Non static function

11. PostMessage compile error: non-static member function

12. illegal call of non-static ...

 

 
Powered by phpBB® Forum Software