473,468 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C++ alternative for PHP's $$variable

1 New Member
Hello,

I need an alternative for PHP`s $$variable in C++.

(In PHP variables go by $variable_name, if you call a variable with an additional "$", you get the content of the variable named as the value of $variable_name.

Example:
$var1 = 'Music';
$Music = 'Rock';

print $$var1 will output Rock)

I need that in C++.
Is there any ?

Thanks.
May 7 '07 #1
1 1409
Banfa
9,065 Recognized Expert Moderator Expert
You need to look into pointers and references, this is basically the same thing, holding a reference to the variable rather than the variable itself.

You example would convert to something like

Expand|Select|Wrap|Line Numbers
  1. // As a reference 
  2. string Music = "Rock";
  3. string &var1 = Music;
  4.  
  5. cout << var1;
  6.  
  7. // As a pointer
  8. string Music = "Rock";
  9. string *var1 = &Music;
  10.  
  11. cout << *var1;
  12.  
References and pointers are similar but the differences are large enough to note including

A reference to a structure/union/class uses the . operator to access members.

A reference can not be changed to reference a different variable once set.

A reference must be initialised when it is declared.
May 7 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: kublai khan | last post by:
I am coming from (an elementary-level) javascript background. I set cookiesin select pages to see where the users are coming from and where they are going. It works quite nicely except that I'd...
12
by: David | last post by:
everywhere I go, i get told "don't use frames, use php instead" ok... so how do i go about it? I want a top banner that doesn't move, and a "contents" type list on the left (that may have a...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
3
by: fasanay | last post by:
Hi everybody I have got the following PHP code which I am trying to convert to ASP any help will be appreciated...I have done most of it but I cant find a replace function for Unset in asp which...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
2
by: sb | last post by:
As the session variable are not recommended, i search for an alternative to store my classe that i use and that i store in that session variable. is that the context that is the alternative? ...
3
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.