Re: Function in header file - newbie VC++/CLI




U¿ytkownik "Jacek" <majly@xxxxxxxxx> napisa³ w wiadomo¶ci
news:f6ec30$aec$1@xxxxxxxxxxxxxxxxxx

Uzytkownik "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> napisal w
wiadomosci news:9t-dncNZl81EPRfbnZ2dnUVZ_ualnZ2d@xxxxxxxxxxxxxx
When you move the function into a cpp file you have to put the class name
in front of it:

void Form1::Status (String ^message)
{
...
}

Otherwise the compiler thinks it is a global function. I.e., not a
member of any class.

--
Scott McPhillips [MVP VC++]

It dosen't resolve problem
Error 1 error C2653: 'Form1' : is not a class or namespace name
c:...\projects\header\header\function.h 5

For example if i make header file like this:
#pragma once

void Status (System::String ^message)


{

message = "global function";



} ;

works good. So problem isn't with that.

Problem occurs when I add to this function any command related with
controls on Form.
For example:

/// function.h

#pragma once

void Status (System::String ^message)


{

message = "global function";

this->MessageBox::Show (message);

} ;

errors:
Error 1 error C2673: 'Status' : global functions do not have 'this'
pointers c:\...\header\function.h 8
Error 2 error C2653: 'MessageBox' : is not a class or namespace name
c:\...\header\function.h 8
Error 3 error C2227: left of '->Show' must point to
class/struct/union/generic type c:\..\header\function.h 8

when i remove this-> errors are:

Error 1 error C2653: 'MessageBox' : is not a class or namespace name
c:\..\header\function.h 8
Error 2 error C3861: 'Show': identifier not found c:\..\header\function.h
8

Problem is with pointer this->. I don't know what it can
replace.



MessageBox will be work if add to header file
using namespace System::Windows::Forms;




.



Relevant Pages

  • [2.6 patch] drivers/char/nvram.c: possible cleanups
    ... This patch contains the following possible cleanups: ... make the needlessly global function __nvram_set_checksum static ... extern void nvram_write_byte ... extern int __nvram_check_checksum; ...
    (Linux-Kernel)
  • [2.6 patch] drivers/char/nvram.c: possible cleanups
    ... make the needlessly global function __nvram_set_checksum static ... extern void nvram_write_byte ... extern int __nvram_check_checksum; ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Function in header file - newbie VC++/CLI
    ... Otherwise the compiler thinks it is a global function. ... I.e., not a member ... #pragma once ... void Status ...
    (microsoft.public.vc.language)
  • Re: [PATCH 3/3] uml: clean our set_ether_mac
    ... global function taking a void* argument. ... You may want to defer this patch to next kernel release. ...
    (Linux-Kernel)
  • Re: sizeof(ptr) = ?
    ... A void * has the same representation as a char *. ... Char pointers which require additional data ... iff the default offset is 0. ...
    (comp.lang.c)