is possible create a any type variable(1 variable that accept any type of values)?
can i create 1 variable that accept any type?
and can i give it the NULL value too?
Re: is possible create a any type variable(1 variable that accept any type of values)
It depends on what exactly you are trying to do. Take a look at Boost.Any for some inspiration.
Re: is possible create a any type variable(1 variable that accept any type of values)
cool.. seems that i can do these:
Code:
void Write(void *var1,void *var2=NULL, void *var3=NULL)
{
cout << var1 << var2 << var3;
}
i just thot do it. and no errors;)
thanks
Re: is possible create a any type variable(1 variable that accept any type of values)
well works fine for a while.. now don't:(
Re: is possible create a any type variable(1 variable that accept any type of values)
No compile error and "works as desired" isn't the same thing.
You have discovered that it is possible to print a pointer to void. This is useful when you want to print an address. However, it is not the same thing as printing a "variable that accept any type of values".
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
laserlight
No compile error and "works as desired" isn't the same thing.
You have discovered that it is possible to print a pointer to void. This is useful when you want to print an address. However, it is not the same thing as printing a "variable that accept any type of values".
true. that's why works in begining and now don't:(
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
Cambalinho
can i create 1 variable that accept any type?
and can i give it the NULL value too?
Giving a variable a NULL value is really only done for pointers. Via casting, a pointer variable can be specified to point to anything - but this is not really recommended!:thumbd:
In c++11, an auto variable can be defined to take the type of the result of the RHS of an assignment, but once defined it retains its type whilst in scope.
See http://msdn.microsoft.com/en-us/library/dd293667.aspx
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
2kaud
Giving a variable a NULL value is really only done for pointers. Via casting, a pointer variable can be specified to point to anything - but this is not really recommended!:thumbd:
In c++11, an auto variable can be defined to take the type of the result of the RHS of an assignment, but once defined it retains its type whilst in scope.
See
http://msdn.microsoft.com/en-us/library/dd293667.aspx
i found something but isn't compatible with Dev C++:(
Code:
// In header: <boost/any.hpp>
class any {
public:
// construct/copy/destruct
any();
any(const any &);
any(any &&);//i get several errors inclued these line:(
template<typename ValueType> any(const ValueType &);
template<typename ValueType> any(ValueType &&);
any & operator=(const any &);
any & operator=(any &&);
template<typename ValueType> any & operator=(const ValueType &);
template<typename ValueType> any & operator=(ValueType &&);
~any();
// modifiers
any & swap(any &);
// queries
bool empty() const;
const std::type_info & type() const;
};
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
i found something but isn't compatible with Dev C++
As per a previous post, using Dev c++ is not recommended:thumbd:
http://clicktobegin.net/programming/...dnt-use-dev-c/
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
2kaud
i'm using it, because i need the compiler exe from MinGW32:(
if i can use the VS compiler or other IDE it's more easy for me:(
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
Cambalinho
i found something but isn't compatible with Dev C++:(
Code:
// In header: <boost/any.hpp>
class any {
public:
// construct/copy/destruct
any();
any(const any &);
any(any &&);//i get several errors inclued these line:(
template<typename ValueType> any(const ValueType &);
template<typename ValueType> any(ValueType &&);
any & operator=(const any &);
any & operator=(any &&);
template<typename ValueType> any & operator=(const ValueType &);
template<typename ValueType> any & operator=(ValueType &&);
~any();
// modifiers
any & swap(any &);
// queries
bool empty() const;
const std::type_info & type() const;
};
That's not what is shown in my copy of boost/any.hpp:confused:
Is not valid c++! So you woudn't find this in a boost file!:eek:
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
2kaud
That's not what is shown in my copy of boost/any.hpp:confused:
Is not valid c++! So you woudn't find this in a boost file!:eek:
i found it: http://www.boost.org/doc/libs/1_54_0/boost/any.hpp
but can i save it .h?
Re: is possible create a any type variable(1 variable that accept any type of values)
is a c++11 rvalue reference feature. If you look at the boost code, you'll see that it's use is guarded by
Code:
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
for when the compiler doesn't support c++11 rvalue references - as dev c++ doesn't.
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
2kaud
is a c++11 rvalue reference feature. If you look at the boost code, you'll see that it's use is guarded by
Code:
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
for when the compiler doesn't support c++11 rvalue references - as dev c++ doesn't.
ok..i see.
but can i convert that temple to a class and use it like a var type?
see these:
template<typename Type1> functioname(){}
can i put in a class for use it normaly like another type?
Re: is possible create a any type variable(1 variable that accept any type of values)
Quote:
Originally Posted by
Cambalinho
i'm using it, because i need the compiler exe from MinGW32:(
I've mentioned to you on other threads that the compiler used by Dev-C++ and MingW is what is important. That compiler happens to be gcc.
The gcc compiler already supports everything that you are looking for.
http://gcc.gnu.org/projects/cxx0x.html
MingW also uses gcc to compile projects. Dev-C++ (once again) is an IDE that just happens to have an old version of gcc already plugged into it. If you take a look at the link I gave you above, and do a little searching on the Internet, you should be able to upgrade MingW to use the latest version of gcc.
The boost libraries are extensively tested with gcc and Visual Studio, and I would say the two platforms that must compile successfully before being accepted by boost.org.
As to IDE's, there is CodeBlocks, which is up-to-date. Do an Intenet search and you will find other IDE's.
Regards,
Paul McKenzie