Solved

class/function w same name

Posted on 2000-05-16
2
177 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
Comment Utility
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
Comment Utility
Thanks abancroft
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 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

10 Experts available now in Live!

Get 1:1 Help Now