0

if i have class CAnalyzer, and i want to make a pointer from this class to new class name CManager. how can i do it? note: i need to make the pointer inside init func in CAnalyzer. thanks

4
  • If you have a class CAnalyzer, you are using the icky Microsoft naming convention where every class starts with a 'C'. If you decide to change it from a class to a structure, you will have to change CAnalyzer to SAnalyzer in every file that references CAnalyzer. Better not to encode data types in names. Commented Jan 6, 2011 at 20:40
  • @Thomas: "class" is not a data type. Commented Mar 18, 2011 at 11:59
  • @Itjax: please state your reference. "With object-oriented programming, a programmer can create new data types to meet application needs. Such an exercise as known as "data abstraction" and the result is a new class of data.", searchsoa.techtarget.com/definition/data-type Commented Mar 18, 2011 at 18:46
  • @Thomas: I'm talking about the keyword "class" (hence no article) which is not a data-type, but an identifier that a data-type definition or declaration will follow. A class (now with an article, hence something that you defined using "class") however is a data-type (which is what you're quoting) - but the class surely doesn't have a data-type (it has a meta-type, which is "class"). Commented Mar 18, 2011 at 19:13

3 Answers 3

3
class CManager;  // Forward declaration (may not be needed)

class CAnalyzer
{
    // Other stuff goes here

private:
    CManager   *p_manager;
};

I don't understand what you mean by "I need to make the pointer inside init func in CAnalyzer".

Sign up to request clarification or add additional context in comments.

1 Comment

+1 I wasnt sure either, but your guess might be more right than mine
0

By init func, did you mean the constructor?

CAnalyzer::CAnalyzer()
{
    CManager *pManager = new CManager();
}

Comments

0

I'm not sure I understand exactly what you're asking, so I will guess.

You want to write a member function of CAnalyzer that returns a pointer to a new instance of a CManager? You can do that like this:

CManager* CAnalyzer::CreateManager()
{
  return new CManager;
}

You should, however, use smart pointers rather than raw pointers in the interest of robust programming.

2 Comments

Shouldn't that be CreateManager?
@DeadMG: Yeah, probably. Fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.