473,657 Members | 2,507 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 1683
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<cha r*>(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<cha r*>(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<cha r*>(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
1609
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 of the Car object and the name of one of its methods. I found one way to get this to work but can someone show me a more orthodox way? Is there a way using references to the object and somehow the method? Python 2.2.2 (#37, Oct 14 2002, 17:02:34)...
5
2746
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
1130
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 NNTP-Posting-Host: b146.dkm.cz 62.24.66.146 Lines: 1 Path:...
4
7007
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 far, my efforts have failed miserably My function takes custom objects as parameters, along the lines of: string MyFunction(XmlNode node, MyNamespace.MyObject myObject, String str) { ... I've tried using delegates, and also MethodInfo, but...
1
1403
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 call outside function. How can I do that? public static void Main() { mycls m = new mycls(); m.run();
4
39202
by: Kylin | last post by:
which situation should use the static function ? -- FireCrow Studio Kylin Garden EMail:w0wd@sohu.com ICQ:156134382
8
4051
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 Developersdex http://www.developersdex.com ***
2
4163
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 code to call static functions attached to each classes like that: foreach($my_array as $classname)
2
1087
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
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.