473,505 Members | 14,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static function calling nonstatic method ? (or something like that)

I have code like this :

void foo(int i, void* p) { .. }
class A
{
public:
A();
~A();

private:
void foobar(int i, char* c);
};

Is there a way for foo to call foobar() ?

Sep 1 '06 #1
3 1671
Lucy Ludmiller wrote:
I have code like this :

void foo(int i, void* p) { .. }

class A
{
public:
A();
~A();
private:
void foobar(int i, char* c);
};

Is there a way for foo to call foobar() ?
Sure:

void foo(int i, void* p)
{
A a;
a.foobar(i, static_cast<char*>(p));
}

But if your question is, can foo call foobar without an instance of
class A to call it with, the answer is no, unless you change foobar to
be a static member of A.

Best regards,

Tom

Sep 1 '06 #2

Thomas Tutone wrote:
Lucy Ludmiller wrote:
I have code like this :

void foo(int i, void* p) { .. }

class A
{
public:
A();
~A();
private:
void foobar(int i, char* c);
};

Is there a way for foo to call foobar() ?

Sure:

void foo(int i, void* p)
{
A a;
a.foobar(i, static_cast<char*>(p));
}
.... if class A declares foo as a friend:
class A
{
friend void foo(int i, void* p) ;
//.....
};

HTH
Radu
>
But if your question is, can foo call foobar without an instance of
class A to call it with, the answer is no, unless you change foobar to
be a static member of A.
you can declaring
Best regards,

Tom
Sep 1 '06 #3
Radu wrote:
Thomas Tutone wrote:
Lucy Ludmiller wrote:
I have code like this :
>
void foo(int i, void* p) { .. }
>
class A
{
public:
A();
~A();
private:
void foobar(int i, char* c);
};
>
Is there a way for foo to call foobar() ?
Sure:

void foo(int i, void* p)
{
A a;
a.foobar(i, static_cast<char*>(p));
}

... if class A declares foo as a friend:
class A
{
friend void foo(int i, void* p) ;
//.....
};
Good point - I missed that foo was private. Thanks for the
clarification.

Best regards,

Tom

Sep 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1591
by: Midas | last post by:
Greetings everyone, I'm including code, for cut/paste, to better explain my question. I create a Car object then I call some of its methods. No problem. Then I try to pass, to a function, the name...
5
2739
by: Marijn | last post by:
I'd like to know how compilers usually handle static variables that are declared inside a function (as opposed to static class-members). Like in: int counter(){ static int c=0; ++c; return c;...
0
1110
by: George Vodpik | last post by:
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <e1$RDGmfEHA.2200@TK2MSFTNGP09.phx.gbl> Newsgroups: microsoft.public.dotnet.general...
4
6996
by: Jonathan Roewen | last post by:
Hi I've got loading assemblies dynamically done (wasn't too difficult). Now I want to lookup a static function in the loaded assembly, and if found, return it somehow, and call it from my app. So...
1
1396
by: Pujo Aji | last post by:
I have a problem with an object calling outside method: Forexample in the main part I have an object and the object will do something time independent, and after it is finished working it should ...
4
39196
by: Kylin | last post by:
which situation should use the static function ? -- FireCrow Studio Kylin Garden EMail:w0wd@sohu.com ICQ:156134382
8
4043
by: csharpula csharp | last post by:
Hello, I am parsing some main arguments and calling to functions according to it. Is it possible not to define the called functions as static? How can I design it better? Thanks *** Sent via...
2
4156
by: PaowZ | last post by:
Hello there! I have to call a bunch of static functions where class names are stored in a array. So I have: $my_array = array("class_1","class_2", ... and so on...) So I tried this piece of...
2
1072
by: Omar.Khalid79 | last post by:
Hi Guys, Maybe this is silly thing to ask but I have a static function declared static void Foo(int a); defined in Foo.cpp and a member method which calls Foo
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.