Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with class and object.

Status
Not open for further replies.

chappy83

Programmer
Mar 10, 2005
2
BE
Hy,

I have a litle problem with the folowing code:

String::String(const String & ori){

tekst = NULL;
set_String(ori);
};

void set_String(const String & ori){
//opppassen voor self reference
if ( this != ori )
{
set_String( ori.get_String() );
}
else
{
cout << "ERROR: self reference !! " << endl;
}
};

Code in the class:
String(const String &);
void set_String(const String &);

And i'm getting the folowing error:
"global functions do not have this pointeres"

 
chappy83 said:
global functions do not have this pointeres

I suspect it's more like "Global functions do not have 'this' pointers."

See the difference?


Error messages aren't just complaints from the compiler. They actually tell you what's wrong. Try reading them.

In this case, you've used the [tt]this[/tt] pointer -- something only usable in member functions -- in a global function.

Solution: you probably meant to declare set_String as a member function, not a global function.
 
Hello,

Now I understand the message, but didn't I declare the function as an member function? Because in the class String a have:

Public:
void set_String(const String &);

So isn't that a member function ?

Thx,
 
Becuase it's publicly declared, it's available outside the function, hence it is considered a global. If you want that function to only be seen within the class, set it to private.

James P. Cottingham
-----------------------------------------
To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.
 
Well, technically, I guess you're right; you did declare it as a member function. You just forgot to define it as one.

You would do that by:
Code:
void [highlight]String::[/highlight]set_String(const String & ori)
{
    ...
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top