I'm trying to use some of the more advanced OO features of Javascript, following Doug Crawford's "super constructor" pattern. However, I don't know how to set and get types from my objects using Javascript's native type system. Here's how I have it now:
function createBicycle(tires) {
var that = {};
that.tires = tires;
that....
I just wonder what's the difference between typeid and typeof in C++?
typeid is defined in standard C++ Library Header File typeinfo.
typeof is defined in the GCC extension for C or in C++ Boost library.
update:
Thank you!
my following test code for typeid does not output the correct type name. what's wrong?
//main.cpp
#inclu...
If I understand correctly, typeid can determine the actual type in polymorphism, while typeof cannot.
Is it also true that their returns are used for different purposes: the return of typeof is used as type keyword that can define variable, but the return of typeid cannot?
Is there any way to both get the actual type for polymorphism a...
I have a class that parses in data from a comma delimited text file. I have an enum for the fields to help me parse data in easier. The class that parses all the records in holds public variables for each field, and of course their variable types. I need to get the type of these variables based on the enum given.
public enum DatabaseFie...
Hi,
How is it possible to learn the name of function I am in?
The below code alerts 'Object'. But I need to know how to alert "Outer."
function Outer(){
alert(typeof this);
}
...
So i have a function that needs to check if an argument is an object, but this fails because:
typeof [] // returns 'object'
This is a classic javascript gotcha, but i cant remember what to do to actually accept objects, but not arrays.
...
I know the type of object (let's say IAnimal) I need to instantiate, and the name (lets say Tiger). How do I write the code to instantiate Tiger, given that the variable that knows the object name is a string. I'm likely missing something simple here, but am currently stuck on this.
Update: I meant Class Tiger : IAnimal, changed abov...
I'm trying to write a macro to make a specific usage of callbacks in C++ easier. All my callbacks are member functions and will take this as first argument and a second one whose type inherits from a common base class.
The usual way to go is:
register_callback(boost::bind(&my_class::member_function, this, _1));
I'd love to write:
re...
hi, very short question.
Is C++ typeof operator standard? de facto standard?
which compilers do not provided it (besides Microsoft C++)?
...
Suppose I'm writing a template function foo that has type parameter T. It gets an object of type T that must have method bar(). And inside foo I want to create a vector of objects of type returned by bar.
In GNU C++ I can write something like that:
template<typename T>
void foo(T x) {
std::vector<__typeof(x.bar())> v;
v.push_b...
I'm using Google Chrome for this test:
Contrary to intuition, the first loop alerts "string" 3 times, while the second loop alerts "number" 3 times.
numarray = [1, 2, 3];
//for-each loop
for(num in numarray)
alert(typeof(num));
//standard loop
for(i=0; i<numarray.length; i++)
alert(typeof(numarray[i]));
I was expecting bot...
It is commonly known that
typeof null
returns "object".
However, I have a piece of code that looks like this:
switch(typeof null){
case "object":
1;
default:
3;
}
This code returns 3.
Why does "object" as returned by typeof null not cause the first branch of the case statement to be executed?
...
I am working on a project where all of our object have a standard base class. We just added some new fields to the database for the tables behind some of the objects e.g. "DateCreated".
I would like to use reflection on the base class' insert method so that when it is called it checks the object to see if it has a property "DateCreated"...
I'm trying to find and run a CompiledQuery given the name. How do I access the compiled query by name and how do I then invoke the delegate?
Here's as far as I can get - I get the error 'Error binding to target method'
public class ActivityRepository
{
private readonly ActivityDataContext _db;
public ActivityRepository()
{...
Hi,
I have a piece of JavaScript code which is expected to set an integer value to a variable.
Something is broken, so when I try to do alert(A);, it returns NaN. isNaN(A); returns true. But if I alert(typeof(A));, it says number.
So how can a variable be a number and not a number at the same time? Maybe I misunderstood what NaN reall...
Hi,
I want to provide the type of an element as parameter to an initialization of an array of pointers to element of an unknown types
something like
void* init(type t)
void* array = malloc(sizeof_type(t)*10));
return array;
}
and later call for example
init(typeof(int))
But I was not able to figure what is the return type ...
I'm used to seeing old code like
if (true)
{
...
}
where it's intuitively clear that someone was being either lazy or overly cautious when making a change. I ran across this snippet today, and I'm curious whether there's a functional difference between doing type comparison this way:
private static bool logField(Type t, string f...
i have the following code:
return "[Inserted new " + typeof(T).ToString() + "]";
but
typeof(T).ToString()
return the full name including namespace
is there anyway to get just the class name (without any namespace qualifiers?)
...
Can we use __typeof__ for input validation in C program run on a Linux platform and how?
If we can't then, are there any ways other than regex to achieve the same?
...
What's it used for if it always returns "object" as type?
--update
always for Elements or lists.
...