473,657 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

Sep 15 '05 #1
4 3712
ar*****@gmail.c om 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
Sep 15 '05 #2
<ar*****@gmail. com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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

Sep 15 '05 #3
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.

Sep 15 '05 #4
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
Sep 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3379
by: ralphNOSPAM | last post by:
Is there a PHP script that can find unused variables? I'd like to 'clean up' my scripts. Thanks...
15
2957
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here is how all the examples I've seen so far create an OleDbCommand Object: Dim cmd as new OleDbCommand("Select * FROM Table1",cnn) I had to figure out that it was the same as this:
12
9606
by: zacks | last post by:
Suddenly, in a VB2005 project I am working on, several variables show up in the list of warnings are being unused local variables. But they all are. Several of them are the ex variable used in a Try/Catch, and the Catch for each one references the ex exception variable. Yet it is still flagged as unused? What gives?
9
3182
by: ThazKool | last post by:
I am just wondering if all the methods that are never called upon during a programs execution are removed when optimizing. For example you have: class FooA { void a(); ... void z(); }
5
6771
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that (1) holds for unmanaged C++ code, but not for managed code. I have class library with both managed and unmanaged static variables that are not referenced by any part of the program. All the
18
2625
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but tweaking the C++ code appears to fix the problem on Linux. I have a static array that is declared privately in one class and a structure that is declared publicly in another class. The program uses both classes. I was getting core dumps and traced...
9
5496
by: werasm | last post by:
Hi all, I'm looking for a nice clean (portable) way to get rid of unused variable warnings without fiddling with compiler settings (on a per case basis). I've come up with this: template <class T> inline void valueUsed( const T& ){} int main()
10
2764
by: Joris Dolderer | last post by:
Hello, I want to compile and link a program statically against the dietlibc. Of course, the dietlibc includes functions my program never needs. Is there any way to throw them out of the final executable? Is there maybe a program that cuts them away from the source code of the dietlibc? I am using gcc. Joris
8
1663
by: fabian.lim | last post by:
Hi, I have a question on constant variables. In the following code snippet, I have a function assign() that takes in an iterator to the private variable v, the number of stuff to assign (int n), and the information to assign (a const pointer to a class object Vector<TYPE>. According to the arrow below, I put a const keyword in the function. To my knowledge, this means that all private variables in this object
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.