Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Identifying created object ? (C++)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 12:05 am    Post subject: Identifying created object ? (C++) Reply with quote

Hello there.
I'm learning to program in c++ and(never programmed before)just hit the
basic of virtual functions.
Now i have a little code that (exersize code) and think i understand what's going on.
But have a question.?
Maybe not the right forum to be asking this question but still gona give it a try.
check the code below.
The code is far from perfect but it's just an exersize code.
Code:
#include <iostream>
using namespace std;

class Human
{
public:
        Human();
        Human( int Twords, int Tmeters) ;
        virtual ~Human(){ cout << " VIRTUAL HUMAN DESTRUCTOR "<< endl; }
        void speak()const;                    // a method to speak
        void walk ()const                     // walk method
{
        for ( int i =0; i < meters; i++)
                cout << "I'm walking I've counted " << i << " Meters so far " << endl;
}

private:
        int words;                      // How many words can a Human say
        int meters;                     // Human walks
};


Human::Human()
{
        words =5;
        meters = 5;
}

Human::Human( int Twords, int Tmeters)
{
        words = Twords;                 // Words
        meters = Tmeters;
}

void Human::speak()const
{
        for ( int i =0; i < words; i++)
                cout << "This is word number " << i << endl;
}



class Man:public Human
{
public:

        Man();
        Man(const Man & rhs);
        virtual ~Man(){ cout <<" VIRTUAL MANS DESTRUCTOR CALLED " << endl;}
        void getName(char * s);                  // get name of our Man
        void printName() const;                // prints trhe name of our
        virtual void speak()const
        {
                cout << "MANS Virtual functions called "<< endl;
                cout << " 'Hello i'm  "<< name << " at your service "<< endl;
        }

private:
        char name[20];                   // holds our name for our man
};


Man::Man():Human()
{
        strcpy(name," I'm a Man " );
}
Man::Man(const Man & rhs)
{
        strcpy(name,rhs.name);
        rhs.printName();
        rhs.speak();


}

void Man::getName(char * s)             // get our name
{
        strcpy(name,s);
}

void Man::printName()const
{
        cout << " Hello my name is " << name << endl;
}



class  Woman:public Human
{
public:
        Woman();
        virtual ~Woman(){ cout << " VIRTUAL WOMAN DESTRUCTOR" << endl;}
        void getName(char * s);
        void printName()const;
        virtual void speak()const
        {
                cout << "Virtual WOMAND functions called " << endl;
                cout << " 'Hello i'm  "<< name << " at your service "<< endl;
        }
private:
        char name[20];
};

// Constructor
Woman::Woman():Human()
{
        strcpy(name,"I'm a woman ");
}


// Accessors
void Woman::getName(char * s)             // get our name
{
        strcpy(name,s);
}

void Woman::printName()const
{
        cout << " Hello my name is " << name << endl;
}

int main()
{
        Man * Man_one = new Man;

        Woman * Woman_one = new Woman;

        Man * Man_two = new Man;

        Woman * Woman_two = new Woman;

        Human * TheDark = new Human;

        Man_one->getName(" Man 1");
        Man_one->printName();
        Man_one->speak();
        Man_one->walk();
        cout << " ------------------------" << endl;
        Woman_one->getName(" Woman 1");
        Woman_one->printName();
        Woman_one->speak();
        Woman_one->walk();
        cout << " ------------------------" << endl;
        Man_two->getName(" Man 2");
        Man_two->printName();
        Man_two->speak();
        Man_two->walk();
        cout << " ------------------------" << endl;
        TheDark->speak();
        TheDark->walk();
        cin.get();
        delete Man_one;
        delete Woman_one;
        delete Man_two;
        delete Woman_two;
        delete TheDark;


        cin.get();
   return 0;
}

Ok this code show the use of virtual functions (basics).
My question is can i identify the object created.
What i mean is when i create an object like
Code:
Man * Man_one = new Man;

i know that this point to that object so when i do THIS.
Code:

#include <iostream>
using namespace std;
class ID_object
{
public:
       ID_object();  // constr
       void printObjectsName(); // Method
};

ID_object::ID_object()
{
//Bla
}

void ID_object::printObjectsName()
{
cout << this ;
}



//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
ID_object * testMe = new ID_object;
testMe->printObjectsName();
cin.get();
delete testMe;

        return 0;
}

This code prints out the memory adres of my object.
What i wanna do is print out the name of the object created.
Is this even possible..??
Or am i way of the road here...??


Please be WARNED that i'm a newbie to C++ and programming just trying
to understand something.
So if yah think it's gonna get complicated, then just tell me to read on.
Or explain it to me as if i where a BABY. :D
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
pygoscelis
Guru
Guru


Joined: 07 Jun 2003
Posts: 409

PostPosted: Thu Jul 10, 2003 12:35 am    Post subject: Reply with quote

What do you mean by obkect's name? What do you want to be printed by this fragment?
Code:
ID_object * testMe = new ID_object;
testMe->printObjectsName();


Another thing: you must declare your functions virtual in the base class (Human) and not in the derived class (Woman), or this won't work as expected:
Code:
Human* whoever = new Woman;
whoever->speak();


I cannot recommend this book strongly enough. If you want to start programming in C++, get it now. Beg on street corners, rob a bookstore, whatever, but get it right now.
Back to top
View user's profile Send private message
zhenlin
Veteran
Veteran


Joined: 09 Nov 2002
Posts: 1361

PostPosted: Thu Jul 10, 2003 3:06 am    Post subject: Reply with quote

The typeof operator should produce an object describing the class of the object, but is not widely supported
Back to top
View user's profile Send private message
pygoscelis
Guru
Guru


Joined: 07 Jun 2003
Posts: 409

PostPosted: Thu Jul 10, 2003 5:56 am    Post subject: Reply with quote

zhenlin wrote:
The typeof operator should produce an object describing the class of the object, but is not widely supported

The typeof operator produces type, not object (in g++ at least). The ANSI/ISO standard typeid operator produces an object. It has a member function name() that returns a character string describing the type of the object. Unfortunately it is not specified what string will be produced by, say, typeid(int).name(), or even that typeid(double).name() will be different from the above. This makes typeid less than useful.

Anyway, typeid should not be used in normal OO code because it breaks substitutability.
Back to top
View user's profile Send private message
iwasbiggs
Apprentice
Apprentice


Joined: 17 Jan 2003
Posts: 203

PostPosted: Thu Jul 10, 2003 8:04 am    Post subject: Re: Identifying created object ? (C++) Reply with quote

The Dark wrote:
Hello there.
...
This code prints out the memory adres of my object.
What i wanna do is print out the name of the object created.
Is this even possible..??
Or am i way of the road here...??


Please be WARNED that i'm a newbie to C++ and programming just trying
to understand something.
So if yah think it's gonna get complicated, then just tell me to read on.
Or explain it to me as if i where a BABY. :D


Things would be best if you had a virtual function that was something like printName() or getID() (much like your already created destructors). Then, man and woman classes would inherit it and it could be changed to be specific as you'd like. So you would call:
Code:

Human * hum = new Man();
hum->printName(); // this will print man's specific function.

_________________
www.ruinedsoft.com
Freeware development.
Back to top
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Thu Jul 10, 2003 10:55 am    Post subject: Reply with quote

Its also possible to use dynamic_cast to test for the type at the end of a base pointer, but then you would have to know what to test for.
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 11:24 am    Post subject: Reply with quote

pygoscelis wrote:
What do you mean by object's name? What do you want to be printed by this fragment?
Code:
ID_object * testMe = new ID_object;
testMe->printObjectsName();


Well maybe i'm thinking the imposisble here, but i wondered if there was a way to print the object name.
Like
Code:

void ID_object::printObjectsName()
{

cout << " Object created is at adress " << this << endl;
cout << " Object created is " << // Here come a functios or somthing that prints the objects name

}


Ok above method can print the adress of the objects it points to :roll:
What i was asking is can it print the objects name.
Output can be something like:
Object adress 1234567 Objects Name is testMe.

pygoscelis wrote:

Another thing: you must declare your functions virtual in the base class (Human) and not in the derived class (Woman), or this won't work as expected:
Code:
Human* whoever = new Woman;
whoever->speak();


Well not clear abouth the virtuals yet because i just hit the chapter.

pygoscelis wrote:

I cannot recommend this book strongly enough. If you want to start programming in C++, get it now. Beg on street corners, rob a bookstore, whatever, but get it right now.
Got myself a mask today.
Gonna prepare myself for the robbery :wink:
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 11:27 am    Post subject: Reply with quote

zhenlin wrote:
The typeof operator should produce an object describing the class of the object, but is not widely supported

Sorry i will have to say . typeof operator Huh...???
Not there yet.
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 12:01 pm    Post subject: Re: Identifying created object ? (C++) Reply with quote

iwasbiggs wrote:
The Dark wrote:
Hello there.
...
This code prints out the memory adres of my object.
What i wanna do is print out the name of the object created.
Is this even possible..??
Or am i way of the road here...??


Please be WARNED that i'm a newbie to C++ and programming just trying
to understand something.
So if yah think it's gonna get complicated, then just tell me to read on.
Or explain it to me as if i where a BABY. :D


Things would be best if you had a virtual function that was something like printName() or getID() (much like your already created destructors). Then, man and woman classes would inherit it and it could be changed to be specific as you'd like. So you would call:
Code:

Human * hum = new Man();
hum->printName(); // this will print man's specific function.

Well i changed the code a little.
check em out.
Code:
   #include <iostream>
using namespace std;

class Human
{
public:
        Human();
        Human( int Twords, int Tmeters) ;
        virtual ~Human(){ cout << " VIRTUAL HUMAN DESTRUCTOR "<< endl; }
        virtual void speak()const;                    // a method to speak
        virtual void walk ()const ;                    // walk method
        virtual void printName() const;       // prints trhe name of our
        void getName(char * s);       // get name


private:
        int words;                      // How many words can a Human say
        int meters;                     // Human walks
        char name[20];
};


Human::Human()
{
        words =5;
        meters = 5;
}

Human::Human( int Twords, int Tmeters)
{
        words = Twords;                 // Words
        meters = Tmeters;
}


void Human::speak()const
{
        for ( int i =0; i < words; i++)
                cout << "This is word number " << i << endl;
}

void Human::walk() const
{
cout << " WALKING " << endl;
}

void Human::printName()const
{
        cout << " Human print method called " << endl;
        cout << " Hello my name is " << name << endl;
}

void Human::getName(char * s)       // get name
{
strcpy(name,s);
}


class Man:public Human
{
public:

        Man();
        Man(const Man & rhs);
        virtual ~Man(){ cout <<" VIRTUAL MANS DESTRUCTOR CALLED " << endl;}
        virtual void getName(char * s);                  // get name of our Man


private:
        char name[20];                   // holds our name for our man
};


Man::Man():Human()
{
        strcpy(name," I'm a Man " );
}

Man::Man(const Man & rhs)
{
        strcpy(name,rhs.name);
        rhs.printName();
        rhs.speak();
}



void Man::getName(char * s)             // get our name
{
        strcpy(name,s);
}




class  Woman:public Human
{
public:
        Woman();
        virtual ~Woman(){ cout << " VIRTUAL WOMAN DESTRUCTOR" << endl;}
        virtual void getName(char * s);

private:
        char name[20];
};

// Constructor
Woman::Woman():Human()
{
        strcpy(name,"I'm a woman ");
}


// Accessors
void Woman::getName(char * s)             // get our name
{
        strcpy(name,s);
}


int main()
{
        Human * Man_one = new Man;

        Human * Woman_one = new Woman;

        Human * Man_two = new Man;

        Human * Woman_two = new Woman;

        Human * TheDark = new Human;

        Man_one->getName(" Man 1");
        Man_one->printName();
        Man_one->speak();
        Man_one->walk();
        cout << " ------------------------" << endl;
        Woman_one->getName(" Woman 1");
        Woman_one->printName();
        Woman_one->speak();
        Woman_one->walk();
        cout << " ------------------------" << endl;
        Man_two->getName(" Man 2");
        Man_two->printName();
        Man_two->speak();
        Man_two->walk();
        cout << " ------------------------" << endl;
        TheDark->getName("The Dark");
        TheDark->printName();
        TheDark->speak();
        TheDark->walk();
        cin.get();
        delete Man_one;
        delete Woman_one;
        delete Man_two;
        delete Woman_two;
        delete TheDark;


        cin.get();
   return 0;
}

Ok now wich
Code:
char name[20]
is being used in this code, not clear on that.
I'm thinking that Man and Woman don't need a private
Code:
char name[20]
declaration, correct me if i'm wrong.
Till later.
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
xr31Daisy
Guru
Guru


Joined: 19 Jul 2002
Posts: 326
Location: Paris, France

PostPosted: Thu Jul 10, 2003 2:10 pm    Post subject: Reply with quote

In Human::printname and Human::setname, you're using name declared in Human ( Human::name ) , in methods of Man, you're using Man's name ( Man::name ) , and in methods of Woman, you're using Woman's name ( Woman::name ).

What you've done is defining 3 differents strings called name, in 3 differents classes. If you want to reuse the same string, you don't need to redefine name in classes Man and Woman.
But since you've declared that name is private in class Human, it means that no derived class can use Human::name. To be able to reuse it, you'll need to declare it as 'protected'.

Note : having different members with the same name in deriving classes is bad practice, because people will have a tendancy not to know which one is used.
What you can try is renaming the names in Man and Woman to man_name and woman_name, and see what happens. ( first thing : code won't compile with an error like "can't access private member 'name' declared in Human " in methods from Man and Woman)
_________________
#include "pictures.h"
Back to top
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Thu Jul 10, 2003 2:49 pm    Post subject: Reply with quote

Its good practice to put a <name of base class>:: qualifier before variable names, most of the time, if you want to access derived members. From what I understand, this is absolutely necessary for template classes (derived members not visible in scope), probably some glitch in the standardization process. In certain cases you want to mask derived members, if you have a common base class with typedefs for instance.

If you want each object to have an individual name, pass it to the constructor. The object has no idea what name you give it in the source code.
Back to top
View user's profile Send private message
pygoscelis
Guru
Guru


Joined: 07 Jun 2003
Posts: 409

PostPosted: Thu Jul 10, 2003 4:00 pm    Post subject: Reply with quote

() wrote:
Its good practice to put a <name of base class>:: qualifier before variable names, most of the time, if you want to access derived members. From what I understand, this is absolutely necessary for template classes (derived members not visible in scope), probably some glitch in the standardization process. In certain cases you want to mask derived members, if you have a common base class with typedefs for instance.

Hm. I know a thing or two about C++, and I never heard about any of the above. Looks suspicious to me, it does.
Back to top
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Thu Jul 10, 2003 5:22 pm    Post subject: Reply with quote

Oops, disregard the template part. I must be going blind, I misread the part totally. There is a potential problem with templates and derivation, which is a template parameter will be masked by a base member with the same name (which doesn't seem right). I can't understand how I got that wrong :\ I was just browsing through C++ Templates by Josuttis and Vandevoorde, looking up the rules for specialization.

Btw: Regarding templates: It is not allowed to specialize member template functions, am I correct?
Back to top
View user's profile Send private message
pygoscelis
Guru
Guru


Joined: 07 Jun 2003
Posts: 409

PostPosted: Thu Jul 10, 2003 6:46 pm    Post subject: Reply with quote

() wrote:
It is not allowed to specialize member template functions, am I correct?

No, it's allowed (but I had to read the standard and search google to answer that :)
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 6:50 pm    Post subject: Reply with quote

xr31Daisy wrote:
In Human::printname and Human::setname, you're using name declared in Human ( Human::name ) , in methods of Man, you're using Man's name ( Man::name ) , and in methods of Woman, you're using Woman's name ( Woman::name ).

What you've done is defining 3 differents strings called name, in 3 differents classes. If you want to reuse the same string, you don't need to redefine name in classes Man and Woman.
But since you've declared that name is private in class Human, it means that no derived class can use Human::name. To be able to reuse it, you'll need to declare it as 'protected'.

Note : having different members with the same name in deriving classes is bad practice, because people will have a tendancy not to know which one is used.
What you can try is renaming the names in Man and Woman to man_name and woman_name, and see what happens. ( first thing : code won't compile with an error like "can't access private member 'name' declared in Human " in methods from Man and Woman)


Yes xr31Daisy your right.
so FIXED The code again.
Code:
   #include <iostream>
using namespace std;

class Human
{
public:
        Human();
        Human( int Twords, int Tmeters) ;
        virtual ~Human(){ cout << "VIRTUAL HUMAN DESTRUCTOR "<< endl; }
        virtual void speak()const;                    // a method to speak
        virtual void walk ()const ;                    // walk method
        virtual void printName() const;       // prints trhe name of our
        void getName(char * s);       // get name


protected:
        int words;                      // How many words can a Human say
        int meters;                     // Human walks
        char name[20];
};


Human::Human()
{
        cout << "DEFAULT CONSTRUCTOR CALLED" << endl;
        words =2;
        meters = 105;
}

Human::Human( int Twords, int Tmeters)
{
        cout << "HUMAN  NON DEFAULT CONSTRUCTOR CALLED " << endl;
        words = Twords;                 // Words
        meters = Tmeters;
}


void Human::speak()const
{
        cout << "Hello there " << name << " How many words can you say ? " << endl;
                for ( int i =0; i < words; i++)
                cout << "Well i can repeat myself " << i << " times " << endl;
                        cout << "Wel Done " << name << endl;
}

void Human::walk() const
{
        cout << "Hi i'm  " << name <<" Goin to WALK  away now " << endl;
        cout << "Think i'm going to WALK about " <<meters << " Meters today " << endl;
}


void Human::printName()const
{
        cout << "Hello my name is " << name << endl;
}

void Human::getName(char * s)       // get name
{

        cout << "TEST: This is HUMAN- CLASS using strcpy(name,s) " << endl;
        strcpy(name,s);
}


class Man:public Human
{
public:

        Man();
        Man(const Man & rhs);
        ~Man(){ cout <<"NON VIRTUAL MANS DESTRUCTOR CALLED " << endl;}

};


Man::Man():Human()
{
        strcpy(name,"THE MAN " );
}

Man::Man(const Man & rhs)
{
        strcpy(name,rhs.name);
        rhs.printName();
        rhs.speak();
}

//--- Begin Class Woman
class  Woman:public Human
{
public:
        Woman();
        ~Woman(){ cout << "NON VIRTUAL WOMAN DESTRUCTOR CALLED" << endl;}

};
// --- End Class Woman


// Constructor
Woman::Woman():Human()
{
        strcpy(name,"A WOMAN ");
}


int main()
{
        Human * Man_one = new Man;

        Human * Woman_one = new Woman;

        Human * Man_two = new Man;

        Human * Woman_two = new Woman;

        Human * TheDark = new Human;

        Man   * Man_object = new Man;

        Woman * Woman_object = new Woman;

        Man_one->getName("MAN 1");     // Get mans name
        Man_one->printName();          // print the name
        Man_one->speak();              // Let man speak
        Man_one->walk();               // Let him walk around
        cout << "------------------------" << endl<< endl;
        Woman_one->getName("WOMAN 1");  // Get womans name
        Woman_one->printName();         // print her name
        Woman_one->speak();             // let her speak
        Woman_one->walk();              // let her walk
        cout << "------------------------" << endl<< endl;
        Man_two->getName("MAN 2");
        Man_two->printName();
        Man_two->speak();
        Man_two->walk();
        cout << "------------------------" << endl<< endl;
        TheDark->getName("The Dark");
        TheDark->printName();
        TheDark->speak();
        TheDark->walk();
        cout << "------------------------" << endl<< endl;
        Man_object->printName();
        Man_object->speak();
        Man_object->walk();
        cout << "------------------------" << endl<< endl;
        Woman_object->printName();
        Woman_object->speak();
        Woman_object->walk();
        cin.get();
        delete Man_one;
        Man_one =0;

        delete Woman_one;
        Woman_one = 0;

        delete Man_two;
        Man_two = 0;

        delete Woman_two;
        Woman_two = 0;

        delete TheDark;
        TheDark = 0;

        delete Man_object;
        Man_object =0;

        delete Woman_object;
        Woman_object = 0;

        cin.get();
   return 0;
}

There only one problem.
When i create these objects

Code:

Man      * Man_object = new Man;
Woman * Woman_object = new Woman;


Should it not call the Man and Woman CONSTRUCTORS ?
Check code.
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
pygoscelis
Guru
Guru


Joined: 07 Jun 2003
Posts: 409

PostPosted: Thu Jul 10, 2003 6:56 pm    Post subject: Reply with quote

The Dark wrote:
Should it not call the Man and Woman CONSTRUCTORS ?

It calls default constructors Man::Man() and Woman::Woman() which don't print anything.
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 7:10 pm    Post subject: Reply with quote

() wrote:

If you want each object to have an individual name, pass it to the constructor.

Hmm thats the whole thing pass wat to the constructor...?
How do or where do you get this name from.
So when i do a (return this) this returns the adress of
the object.
OK let me get this up in the air.
From what i have been reading so far.
A class is just a user made type (with bunch of cool code int it to use :D).
And if you have a class with the name Help.
You create an object like this Help Myobject ,am i right.
Do i hear a AMEN.

So how do you get this objectname. ( are we still on the same boat ? :D ).

() wrote:

The object has no idea what name you give it in the source code


MAYDAY MAYDAY.............. 8O
So its a mission impossible :?
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Thu Jul 10, 2003 7:12 pm    Post subject: Reply with quote

pygoscelis wrote:
() wrote:
It is not allowed to specialize member template functions, am I correct?

No, it's allowed (but I had to read the standard and search google to answer that :)
Doesnt seem that way here, or there's something wrong with my syntax. g++ chokes on it, Intel C++ allows it untill I specify -ansi. My syntax looks like this:
Code:

class Something {
    template<CoordSelect coordSelect>
    void realTransform(const Matrix4x4 &mt, int i);

    template<>
    void realTransform<transformLocalOnly>(const Matrix4x4 &mt, int i) {
        vlist_[i] = mt*vlist_[i];
    }
};
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 7:13 pm    Post subject: Reply with quote

pygoscelis wrote:
The Dark wrote:
Should it not call the Man and Woman CONSTRUCTORS ?

It calls default constructors Man::Man() and Woman::Woman() which don't print anything.


Yes i saw the error Thanks .
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Thu Jul 10, 2003 7:19 pm    Post subject: Reply with quote

The Dark wrote:
() wrote:

If you want each object to have an individual name, pass it to the constructor.

Hmm thats the whole thing pass wat to the constructor...?

If you want the object to have a certain name, it will have to contain a string variable, which can be initialized in the constructor. An example:
Code:

class KnowMyName {
public:
    KnowMyName(const std::string &name) : name_(name) {}

    void printName() { std::cout << name_ << "\n"; }   
 
private:
    std::string name_;
};

There's no way of getting a handle to the object variable's name, its just a symbol in the source code. If you want to give it a name, youll have to do it manually. But whats the big deal? If you want to recognize individual objects, assign them ID's or something.
Back to top
View user's profile Send private message
The Dark
Tux's lil' helper
Tux's lil' helper


Joined: 01 Feb 2003
Posts: 126
Location: BACK ON PLANET GENTOO

PostPosted: Thu Jul 10, 2003 7:27 pm    Post subject: Reply with quote

() wrote:
The Dark wrote:
() wrote:

If you want each object to have an individual name, pass it to the constructor.

Hmm thats the whole thing pass wat to the constructor...?

If you want the object to have a certain name, it will have to contain a string variable, which can be initialized in the constructor. An example:
Code:

class KnowMyName {
public:
    KnowMyName(const std::string &name) : name_(name) {}

    void printName() { std::cout << name_ << "\n"; }   
 
private:
    std::string name_;
};

There's no way of getting a handle to the object variable's name, its just a symbol in the source code. If you want to give it a name, youll have to do it manually. But whats the big deal? If you want to recognize individual objects, assign them ID's or something.


Clear that up.
No it wasn't a big deal just asked if this was possible. but i get it now.
Just a stupid newbie question.
But thanks for clearing the mist in my brain. :D
Going to experiment a little further(gonna try your code).
Later.
_________________
-=The Dark=-
Linux Rules
i686 Pentium III (Coppermine) GenuineIntel
http://www.gentoo.org
Back to top
View user's profile Send private message
pygoscelis
Guru
Guru


Joined: 07 Jun 2003
Posts: 409

PostPosted: Thu Jul 10, 2003 7:33 pm    Post subject: Reply with quote

() wrote:
My syntax looks like this:
Code:

class Something {
    template<CoordSelect coordSelect>
    void realTransform(const Matrix4x4 &mt, int i);

    template<>
    void realTransform<transformLocalOnly>(const Matrix4x4 &mt, int i) {
        vlist_[i] = mt*vlist_[i];
    }
};

You need to specialize outside of the class (at namespace scope):
Code:

template<>
void Something::realTransform<transformLocalOnly> (const Matrix4x4 &mt, int i) {
  vlist_[i] = mt*vlist_[i];
}
Back to top
View user's profile Send private message
()
l33t
l33t


Joined: 25 Nov 2002
Posts: 610

PostPosted: Thu Jul 10, 2003 9:05 pm    Post subject: Reply with quote

Thanks, youre right. I must be getting rusty :\
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum