Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

class/function w same name

Posted on 2000-05-16
2
Medium Priority
?
244 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
2 Comments
 
LVL 4

Accepted Solution

by:
abancroft earned 120 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

824 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