class in other class

Started by
1 comment, last by paneb 21 years ago
is it alright to have a pointer to another class as a member of another class? in code:

class CLASS1   {
...
};

class CLASS2   {
private:
 CLASS1 pt;
...
};
 
and then in the constructor i would allocate memory for pt..is that alright? i am asking because i dont want to be doing something absurd.. thanks [blocks are apparently case sensitive] [edited by - Magmai Kai Holmlor on April 18, 2003 12:33:44 AM]
Advertisement
Yeah, having pointer is fine, though you might want to consider using a smart pointer. It''s just easier iff you use the right type of smart pointer, the ones in boost are probably the easiest to use.

However, naming classes in ALLCAPS is bad style (it''s legal code though). Traditionally, ALLCAPS is reserved for MACROS_ONLY.

- Magmai Kai Holmlor

"Nobody will listen to a stone no matter how hard you throw it."

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
[Free C Libraries | zlib ]

- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
alright, thanks..i''ll follow your advice for the naming..its just i dont like the CName way of doing it

This topic is closed to new replies.

Advertisement