![]() |
Unused variables used for class constructors
Hi,
I'm using some lines of code like this: ClassName *var = new ClassName(...); and that's it. The class constructor does everything I want (there are methods to do more but I don't need them) But this generates a warning (gcc4) saying it's an unused variable. Is there a better way to do this? |
Re: Unused variables used for class constructors
artooro@gmail.com wrote:
> Hi, > > I'm using some lines of code like this: > ClassName *var = new ClassName(...); > > and that's it. The class constructor does everything I want (there are > methods to do more but I don't need them) > But this generates a warning (gcc4) saying it's an unused variable. > Is there a better way to do this? > Well a better way is ClassName var(...); Why use new when you don't have to? Whether that gets rid of your warning or not is another matter. Compiler warnings are often dubious. john |
Re: Unused variables used for class constructors
<artooro@gmail.com> wrote in message
news:1126820173.261337.218570@f14g2000cwb.googlegr oups.com... > I'm using some lines of code like this: > ClassName *var = new ClassName(...); > > and that's it. The class constructor does everything I want (there are > methods to do more but I don't need them) > But this generates a warning (gcc4) saying it's an unused variable. > Is there a better way to do this? Even though g++ specific issues are off-topic here, I can come up with two solutions: int g_i = 0; class ClassName { public: ClassName(int i) { g_i += i; // everything I need } }; #include <iostream> void do_it(ClassName const &) {} int main() { // one way do_it(ClassName(1)); // another way ClassName var(1) __attribute__((unused)); } Ali |
Re: Unused variables used for class constructors
Well your suggestions which I have tried before but forgot about don't
work. It seems this class only work using this method. (wxWidgets stuff) No big problem though. |
Re: Unused variables used for class constructors
On Thu, 15 Sep 2005 14:36:13 -0700, artooro wrote:
> Hi, > > I'm using some lines of code like this: > ClassName *var = new ClassName(...); > > and that's it. The class constructor does everything I want (there are > methods to do more but I don't need them) > But this generates a warning (gcc4) saying it's an unused variable. > Is there a better way to do this? If you don't need the var, then don't use it: new ClassName(...); I'm assuming there's some reason you don't need to delete it (like it deletes itself). - Jay |
| All times are GMT. The time now is 06:31 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.