Function in header file - newbie vc++



 DEVELOP > c-Plus-Plus > Function in header file - newbie vc++

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Jacek"
Date: 03 Jul 2007 11:28:10 AM
Object: Function in header file - newbie vc++
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.
.

User: "gpuchtel"

Title: Re: Function in header file - newbie vc++ 03 Jul 2007 03:15:28 PM
On Jul 3, 12:28 pm, "Jacek" <m...@gazeta.pl> wrote:

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)
{
}
.
User: "Jacek"

Title: Re: Function in header file - newbie vc++ 03 Jul 2007 05:06:00 PM
Uzytkownik "gpuchtel" <gpuchtel@gmail.com> napisal w wiadomosci
news:1183493728.356726.205700@n2g2000hse.googlegroups.com...

On Jul 3, 12:28 pm, "Jacek" <m...@gazeta.pl> wrote:

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)
{
}

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

Title: Re: Function in header file - newbie vc++ 03 Jul 2007 07:12:15 PM
On Jul 3, 6:06 pm, "Jacek" <m...@gazeta.pl> wrote:

Uzytkownik "gpuchtel" <gpuch...@gmail.com> napisal w wiadomoscinews:1183493728.356726.205700@n2g2000hse.googlegroups.com...



On Jul 3, 12:28 pm, "Jacek" <m...@gazeta.pl> wrote:

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)
{
}


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

A reference (or pointer) to an (object) instance of a class.
.



User: "Obnoxious User"

Title: Re: Function in header file - newbie vc++ 03 Jul 2007 11:31:03 AM
On Tue, 03 Jul 2007 18:28:10 +0200, Jacek wrote:

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.
--
Obnoxious User
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER