Solved

class/function w same name

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
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 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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now