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



If you are showing all of the code, your problem is that your function is not part of a class and, thus, wouldn't have a 'this' pointer. You don't really need to expressly use the this pointer anyway since it is implied where it can be used.

That said there really isn't any good reason to put a function like this into the .h file. If you did, though, you'd likely want to define it and put the body right after it so as not to be confusing:

class MyClass
{
// Other stuff for class

void Status() {
// Whatever it does
};
}

You will also want to make sure that richTextBox1 points to a valid window before trying to call functions in that object.

Tom

"Jacek" <majly@xxxxxxxxx> wrote in message news:f6dvn3$8m3$1@xxxxxxxxxxxxxxxxxx
Hi All,

I'm newbie in programing and first time try move function to header file.
I have simple function declered on Form1.h

void Status (String ^message){

this->richTextBox1->AppendText(message+"\n");
this->richTextBox1->ScrollToCaret(); }
it's work good on this form i.e on event button.click :

Status ("Hello world");


I'd like move this function to header file function.h and function.cpp

In file function.h are declaration like this:

#pragma once
void Status (System::String ^message);

In file function.cpp I added body of the function:

#include "function.h"
#include "stdafx.h"

void Status (System::String ^message){


this->richTextBox1-> AppendText(message+"\n");
this->richTextBox1-> ScrollToCaret();

};

Unfortunately it doesn't work. I lost a lot of time to resolve error but
without result.
I don't know how replace pointer this->

Error from VC++:

.\function.cpp(11) : error C2673: 'Status' : global functions do not have
'this' pointers
.\function.cpp(11) : error C2227: left of '->richTextBox1' must point to
class/struct/union/generic type
.\function.cpp(11) : error C2227: left of '->AppendText' must point to
class/struct/union/generic type
.\function.cpp(12) : error C2673: 'Status' : global functions do not have
'this' pointers
.\function.cpp(12) : error C2227: left of '->richTextBox1' must point to
class/struct/union/generic type
.\function.cpp(12) : error C2227: left of '->ScrollToCaret' must point to
class/struct/union/generic type

Where I made error ? Please help.




.