09-05-2005
Quote:
Originally Posted by arun.viswanath
Can any one explain how the statement '2' in the following statements is a legal one.
int & ref = 3; // Illegal statement - Compiler error.
const int& ref=3 ; // Compile and executes properly.
Thanks in Advance,
Arun
Arun,
value of '3' is a constant hence it can only be assigned to a const reference. below example will help you to understand better.
likewise say if you have:
int a=3;
int &b = a; //this is perfectly legal
const int &c = a; //this is legal
while if you had
const int a=3;
int &b = a; //illegal because : cannot convert from 'const int' to 'int &'
const int &c = a; //this is legal
rishi
9 More Discussions You Might Find Interesting
1. Programming
hi,
what is the difference b/w char in C and C++.and give me the examples.
Thanks...
sarwan (3 Replies)
Discussion started by: sarwan
3 Replies
2. Red Hat
Hello everey one,
here i am attempting to compile a c++ project .it's throughing the following errors.
my machine details are as follows:
Linux chmclozr0119 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
errors:
=====
Generating... (0 Replies)
Discussion started by: mannam srinivas
0 Replies
3. Programming
Is it possible to have a non-const reference variable as an OPTIONAL/DEFAULT parameter to c++ function
ex
void read(string &data,int &type=0 /*or something*/) ;
so i will call
read(data);
//or
int type;
read(data,type);
printf("Type =%d",type);
I found one dirty workaround
... (2 Replies)
Discussion started by: johnbach
2 Replies
4. Programming
Hi all,
I have some questions about functions.
In a code I have (a .hpp file) there is this line which says:
const Class_1_Name* Class_2_Name::MethodName(int ipart) const {return (ClassName*)_ref_to_method.At(ipart);}
My questions are:
What is the meaning of the two constants,... (2 Replies)
Discussion started by: eager2no
2 Replies
5. Programming
Is it permitted to type-cast a member variable passed in as a parameter in a member const method ..
I am doing something like :
in a
return-type method () const {
variable other = long(member variable)
}
this other assigned variable is not updating and I wonder if type-casting in such... (1 Reply)
Discussion started by: shriyer123
1 Replies
6. Programming
Hi
In the following code, why the variable 'i' still retains the value 10 instead of 11? Why it is not possible to alter this variable's value?
int main() {
const int i = 10;
*(const_cast<int*>(&i)) = 11;
cout << i << endl; // Ans: 10
} (6 Replies)
Discussion started by: royalibrahim
6 Replies
7. Programming
I am writing some code in C++ to print a message using fprintf
Here is an example
void pr_desc(
FILE* stream,
int shift,
const char* desc) {
const char* format="%*s\e;
fprintf(stream,format,shift,"",desc);
}
I call it using
const char* desc;
... (4 Replies)
Discussion started by: kristinu
4 Replies
8. Shell Programming and Scripting
Guys,
May i know how can we de reference the code reference variable.?
my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";};
print $a->(4,5);
How can we print the whole function ?
Please suggest me regarding this.
Thanks for your time :)
Cheers,
Ranga :) (0 Replies)
Discussion started by: rangarasan
0 Replies
9. Programming
Dear all,
I am using C and ROOT for programming. And I need to incorporate following in my code.
char *fps=NULL;
int dec=0,sign=0;
float mean = h1->GetMean(1); //0.001298
fps= fcvt(mean,6 , &dec, &sign);
I need to provide this mean as const char to some other function to get... (8 Replies)
Discussion started by: emily
8 Replies
LEARN ABOUT DEBIAN
zipios_simplesmartpointer
zipios::SimpleSmartPointer(3) Library Functions Manual zipios::SimpleSmartPointer(3)
NAME
zipios::SimpleSmartPointer -
SimpleSmartPointer is a simple reference counting smart pointer template.
SYNOPSIS
#include <simplesmartptr.h>
Public Member Functions
Type * operator-> () const
Type & operator* () const
SimpleSmartPointer (Type *p=0)
template<class T2 > SimpleSmartPointer (const SimpleSmartPointer< T2 > &src)
SimpleSmartPointer (const SimpleSmartPointer &src)
template<class T2 > SimpleSmartPointer & operator= (const SimpleSmartPointer< T2 > &src)
SimpleSmartPointer & operator= (const SimpleSmartPointer &src)
SimpleSmartPointer & operator= (Type *src)
bool operator== (const Type *p) const
bool operator!= (const Type *p) const
bool operator== (const SimpleSmartPointer &sp) const
bool operator!= (const SimpleSmartPointer &sp) const
bool operator! () const
operator void * () const
Type * get () const
unsigned int getReferenceCount () const
Returns the reference count - For debugging purposes.
Detailed Description
template<class Type>class zipios::SimpleSmartPointer< Type >
SimpleSmartPointer is a simple reference counting smart pointer template.
The type pointed to must keep a reference count that is accessible through the two methods void ref() const and unsigned int unref() const.
The type must also handle the reference count properly. The easiest way to do that is to use the ReferenceCount template class.
Definition at line 15 of file simplesmartptr.h.
Member Function Documentation
template<class Type> unsigned int zipios::SimpleSmartPointer< Type >::getReferenceCount () const [inline]
Returns the reference count - For debugging purposes.
Definition at line 67 of file simplesmartptr.h.
Author
Generated automatically by Doxygen for Zipios++ from the source code.
Zipios++ Mon Oct 10 2011 zipios::SimpleSmartPointer(3)