Function in header file - newbie vc++

J

Jacek

Hello
I'm very 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.
 
O

Obnoxious User

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

void Status (String ^message){

Looks like C++/CLI, which is *not* C++. Try one
of microsofts C++/CLI newsgroups instead.
 
G

gpuchtel

Hello
I'm very 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.

'this' exists only in the context of a class. Did you forget to
specify the class name?

void YourClassName::Status (System::String ^message)
{
}
 
J

Jacek

Uzytkownik "gpuchtel said:
'this' exists only in the context of a class. Did you forget to
specify the class name?

void YourClassName::Status (System::String ^message)
{
}

I don't want new class, only global function.
Yes, I agree wiht 'this' but what have to replace it ?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,282
Latest member
RoseannaBa

Latest Threads

Top