Solved

class/function w same name

Posted on 2000-05-16
2
228 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

624 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