Changing type name


 
Thread Tools Search this Thread
Top Forums Programming Changing type name
# 1  
Old 01-27-2012
Changing type name

In C++, how can I change the type with another name

For example

How can I declaring an object real which would be the same as declaring it float
# 2  
Old 01-27-2012
Are you referring to typedef?

Code:
typedef float real;

int main(int argc, char **argv)
{
    real val = 10.1;
  
    return 0;
}

--ahamed
# 3  
Old 01-27-2012
Yes. I have a lot of programs and classes in various files and I have created
Code:
common.h

The contents are
Code:
#ifndef Common_hh
#define Common_hh

#include <stdlib.h>

typedef float Real;

#endif

Then I include it with the #include in the files
# 4  
Old 01-27-2012
Is your question answered then, or is there more to it?
# 5  
Old 01-27-2012
I have defined a function in a class called GetFloat and want to be able to call it using GetReal. Is this possible for class functions?

Using g++ I use the compiler option
Code:
-DGetReal=GetFloat

I want now to have it in the actual code
# 6  
Old 01-28-2012
If that already works, it's equivalent to #define GetReal GetFloat

It's a global text replacement that only matches whole words, essentially, so would match a bare GetFloat nearly anywhere, including the class you want, and anywhere else you don't want too.

The usual way to change the name of a function in C++ would be to change the name of the function. Or if you really need both names, create an inline wrapper so it has two names.
Code:
float getReal(void) { return(value); }
inline float GetFloat(void) { return(GetReal()); }

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to know the file type

Hi I am doing some operation in which files will be dumped in Specific location. I want to know the File type.i.e i am expecting CSV files. So i want to write a script so that i can check the file which are dumped are in CSV Files.xxxx.csv format. (2 Replies)
Discussion started by: Aditya.Gurgaon
2 Replies

2. UNIX for Advanced & Expert Users

changing shell type from sh to ksh

Could someone please advise, what's the best way to changing the shell type from sh to ksh. When I login into a unix server it takes you directly to sh, is there a way of amending the .profile to use ksh instead. Or is there some other way ? Ideally it would be good to be done from the login... (10 Replies)
Discussion started by: venhart
10 Replies

3. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

4. Shell Programming and Scripting

String type to date type

Can one string type variable changed into the date type variable. (1 Reply)
Discussion started by: rinku
1 Replies

5. Shell Programming and Scripting

Changing userID and Changing group and GID

Hello, I want to write a ksh script about changing UID and changing group with GID. There are multiple servers i want to perform that job. linux1 linux2 linux3 linux4 linux5 ...... . . . . . 1.) How can i enter "password" in script rather asking me? I was trying this... ssh... (2 Replies)
Discussion started by: deal732
2 Replies

6. UNIX for Dummies Questions & Answers

Lynx - Downloading - extension handling - changing mime type?

Using Lynx, when I try to download a .rar, it confirms I want to download and its got it as an appication/rar file. However, split archives that end in .r## (.r00, .r01 ...) are not recognized as an appication/rar file and it reads the file like a .txt or .html. How can I fix this? Thanks! (2 Replies)
Discussion started by: yitzle
2 Replies

7. Shell Programming and Scripting

Different type of shells?

Hello there, i just want to know what are the different type of shells and the main difference betwee them. The problem is that if you try to search over the net you will find a lot of information and hence you will have no enough time to read all of them.....Anyone can help with this?? (1 Reply)
Discussion started by: charbel
1 Replies

8. UNIX for Dummies Questions & Answers

you have more and one unix type?

As a formem unix newbe I Just wanted to tell you about this cool site for all you confused people. If you need to support more than one unix type: Use this one. It's a life saver. http://www.unixguide.net/unixguide.shtml here (4 Replies)
Discussion started by: sunbird
4 Replies

9. Post Here to Contact Site Administrators and Moderators

OS Type and Version

I have seen quite a few posts recently which have launched into questions about specfic errors whose resolution depends a lot upon the OS type and version. I suggest that in the FAQ an additional entry be included, either under general board usage or posting threads, that informs the user to... (6 Replies)
Discussion started by: saabir
6 Replies
Login or Register to Ask a Question