Solved

class/function w same name

Posted on 2000-05-16
2
220 Views
Last Modified: 2010-04-02
Quick n easy, I hope
I have defined a class
class module{
   void(*method)(void)
};

and an object of that class:
module firstlatt;

I have defined a function with the same name:
void firstlatt(void){}

and I want to make the 'method' pointer point to this function.

What is the correct syntax for assigning the pointer?

Thank you
0
Comment
Question by:glebspy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
abancroft earned 30 total points
ID: 2814627
You can't do have the variable & function of the same name in scope of each other. You'll have to either use different names or use namespaces

e.g. (renaming)
class module {
public:  // <--- NEW
   void(*method)(void) ;
};

void firstlatt(void){}

module mFirstLatt; // <-- NEW NAME

int main(int argc, char* argv[])
{
  mFirstLatt.method = firstlatt;

  return 0;
}

e.g. (namespaces)
class module {
public:  // <--- NEW
   void(*method)(void) ;
};

namespace module_funcs {
void firstlatt(void){}
};

module firstlatt; // <-- NEW NAME

int main(int argc, char* argv[])
{
      firstlatt.method = module_funcs::firstlatt;

      return 0;
}
0
 
LVL 1

Author Comment

by:glebspy
ID: 2814678
Thanks abancroft
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question