cambalinho 142 Practically a Posting Shark

the only way is to use the argument(not parameter) 'nullptr':
instead use the functioname, we use the 'nullptr' and works fine(i have tested).

cambalinho 142 Practically a Posting Shark

thanks for all.. thanks to both

cambalinho 142 Practically a Posting Shark

(sorry Mike_2000_17)
Mike_2000_17: "Why not? It's a perfectly fine function, and should work for strings. What is it that is not working with strings? What happens? And why do you want it to do?"
because i need casting the string, or the 'cout' will give me an error. i don't know why. but with casting it's working fine;)

cambalinho 142 Practically a Posting Shark

i have 2 questions:

1 - why some C++ PRO don't advice me use these code?(making properties)

2 - can i put these 2 parameters optionals?
- void (Container::setptr)(ValueType t)
- ValueType (Container::
getptr)()

i try assigment them to NULL, but i can't use an empty argument, because gives me errors. can anyone explain to me more?

cambalinho 142 Practically a Posting Shark

sorry for that. and thanks for correct me

cambalinho 142 Practically a Posting Shark

thanks for the information... thanks for all

cambalinho 142 Practically a Posting Shark
int multi(int a, int b)
{
    return (a*b);
}

int main()
{
    int a=0;
    a=multi(20,30);
    cout <<a;
    cin.get();
}

i hope these help you more;)

cambalinho 142 Practically a Posting Shark

i have 1 question: for use dynamic arrays, can i use normal variables instead pointers?

cambalinho 142 Practically a Posting Shark

heres a nice books for start and more:
C : http://www.tutorialspoint.com/cprogramming/index.htm
C variadic functions: http://en.cppreference.com/w/cpp/utility/variadic
C++ : http://www.tutorialspoint.com/cplusplus/index.htm
(these tutorials can be download from there too)
C++ properties: http://www.daniweb.com/software-development/cpp/threads/462365/how-can-i-create-properties

C++ events: http://www.astahost.com/info/fttcmp-basic-event-handler-class-familiar-handlers-mimic.html
(isn't 100%, but maybe can help someone.. or see my topics)

C++ 11 Variadic functions: http://nerdparadise.com/forum/openmic/5712/
not C++11: http://en.cppreference.com/w/cpp/utility/variadic
(they use recursive functions)

for Windows API:
http://www.winprog.org/tutorial/start.html
and
http://www.zetcode.com/gui/winapi/
i hope that help someone

cambalinho 142 Practically a Posting Shark

because in line 31 you never used an 'if';)

do 
  {
  cout<<"How many days?"<<endl;
  cin>>days;
  if (days<0) cout<<"You enter a negative number,please try again."<<endl;
 }while (days < 0);

i hope help you

cambalinho 142 Practically a Posting Shark

the:

person2 person2,f;

it's incorrect sorry about that:(
i can't use 'static' members because i need inicializate the variables outside why i want that type of class?
because of 2 things:
1 - if i need use a class without objects... these is the best way;
2 - imagine with virtual functions, you can do a new class diretive of the class base. so i can use the new class without objects.(is for simulate events).
but thanks for your advice

cambalinho 142 Practically a Posting Shark

As their name implies, they shift the bits to the left or right. In other words, the bits are moved to the left or right by the given amount of positions. If I take the number 13, I get this:

For left-shift:

13 == 1101 == 13
13 << 1 == 11010 == 26
13 << 2 == 110100 == 52
13 << 3 == 1101000 == 104
And for right-shift:

13 == 1101 == 13
13 >> 1 == 110 == 6
13 >> 2 == 11 == 3
13 >> 3 == 1 == 1
13 >> 4 == 0 == 0
I don't think there is a way to put it more clearly than that.

you said that???

For left-shift:
13 << X put the X zeros on right side(like i see from your sample)

for right-shift:
13 << X delete the digits from right to left. the X is the number of digits be deleted until '0'
(if i'm wrong, please tell me)
thanks to both;)

cambalinho 142 Practically a Posting Shark

heres a nice way for build 1 class 100% 'static':

class classname
{
    //class menbers... normal way(don't use static, because it's more easy)
}classname;

now you don't need a object for use the class. but if you need a object just change the last line:

class classname
    {
        //class menbers... normal way(don't use static, because it's more easy)
    }classname, object1, object2, objectn;

now the class can be used with it's name and it's objects...
(now i did 1 test)
when you declare a class objects, you can use the name too:

person2 person2,f;

cool;)

cambalinho 142 Practically a Posting Shark

the C\C++ have several ways\function for convert them.
the >> and << are dificulty to understand:(
sorry, if i insist... but seem very difulty to understand.
i see that we convert decimal to binary:

10d=1010b
understood. but how and what is moved?
(my problem isn't the convertion between decimal and binary, but what << and >> do:()

cambalinho 142 Practically a Posting Shark

heres how we can do a function parameter:

void (Container::*setptr)(ValueType t)

or

ValueType (Container::*getptr)()

(remember these way only use the function name)

sample:

&classname::setfuntionname

i have 1 question: how can i make it optional? or igual a NULL\nullptr?

cambalinho 142 Practically a Posting Shark

now it's more cool:

/*how use properties:

- inside class constructor do these:
    PropertyName.setContainer(this);

- inside the class but outside the class members(but after the GetFunction and\or SetFunction) do these:
    property <ClassName,PropertyType,&ClassName::SetFunction,&ClassName::GetFunction> PropertyName;

- more information:
    - for ReadOnly we use 'nullptr'(and not NULL, because they are pointers) on &ClassName::GetFunction as argument;
    - for WriteOnly we use 'nullptr'(and not NULL, because they are pointers) on &ClassName::SetFunction as argument;

*/


#ifndef PROPERTY_H_INCLUDED

#define PROPERTY_H_INCLUDED

#include <iostream>
#include <assert.h>

using namespace std;

template <typename Container, typename ValueType, void (Container::*setptr)(ValueType t),ValueType (Container::*getptr)()>
class property
{
public:
    property()
    {
        m_cObject= NULL;
        Set = setptr;
        Get = getptr;
    }

    void setContainer(Container* cObject)
    {
        m_cObject = cObject;
    }

    //-- Overload the '=' sign to set the value using the set
    //   member --
    ValueType operator =(const ValueType& value)
    {
        assert(m_cObject != NULL);
        assert(Set != NULL);
        (m_cObject->*Set)(value);
        return value;
    }


    //-- To make possible to cast the property class to the
    //   internal type --
    operator ValueType()
    {
        assert(m_cObject != NULL);
        assert(Get != NULL);
        return (m_cObject->*Get)();
    }

    friend istream &operator>>( istream  &input, property &d )
    {
        ValueType v;
        input >>v;
        d = v;
        return input;
    }

    friend istream& getline (istream&  is, property &str)
    {
        ValueType v;
        getline(is,v);
        str = v;
        return is;
    }

private:
  Container* m_cObject;  //-- Pointer to the module that
                         //   contains the property --
  void (Container::*Set)(ValueType value);
                         //-- Pointer to set member function --
  ValueType (Container::*Get)();
                         //-- Pointer to get member function --
};

#endif // PROPERTY_H_INCLUDED

but seems that i can't …

cambalinho 142 Practically a Posting Shark

these is the best i came with:

class person
{
private:
    string name;
public:
    virtual void changed()
    {
        cout <<"";
    }
    person()
    {
        Name.setContainer(this);//these is from my property header file
    }
    void setname(string value)
    {
        name=value;
        changed();
    }

    string getname()
    {
        return name;
    }
    property <person,string,&person::setname,&person::getname> Name;//these is from my property header file
};

class joana : public person
{
    void changed()
    {
        cout << "joana name changed" << endl;
    }
}joana;

class ana : public person
{
    void changed()
    {
        cout << "ana name changed" << endl;
    }
}ana;

int main()
{

    joana.Name="ana";
    cout <<(string) joana.Name<< endl;
    ana.Name="joana";
    cout <<(string) ana.Name<< endl;

    //person2.Name="joaquim";
    //cout <<(string) person2.Name;
    return 0;
}

but i need ask anotherthing:
when i do:

class classname
{
     //class members
}classname;

why i can't do objects from classname?
(these is best solution that i found for events)
when i do:

person2 f;

i get these error:
"C:\Users\Joaquim\Documents\CodeBlocks\testevents\main.cpp|84|error: expected ';' before 'f'|"

cambalinho 142 Practically a Posting Shark

sorry not that:(
see my tamplate class:

template <typename Container, typename ValueType, int nPropType=3>
class property
{
public:
    property()
    {
        m_cObject = NULL;

            Set = NULL;

            Get = NULL;
    }


    //-- This to set a pointer to the class that contain the
    //   property --
    void setContainer(Container* cObject)
    {
        m_cObject = cObject;
    }


    //-- Set the set member function that will change the value --
    void setter(void (Container::*pSet)(ValueType value))
    {
        if((nPropType == WRITE_ONLY) || (nPropType == READ_WRITE))
            Set = pSet;
        else
            Set = NULL;
    }


    //-- Set the get member function that will retrieve the value --
    void getter(ValueType (Container::*pGet)())
    {
        if((nPropType == READ_ONLY) || (nPropType == READ_WRITE))
            Get = pGet;
        else
            Get = NULL;
    }


    //-- Overload the '=' sign to set the value using the set
    //   member --
    ValueType operator =(const ValueType& value)
    {
        assert(m_cObject != NULL);
        assert(Set != NULL);
        (m_cObject->*Set)(value);
        return value;
    }

    //-- To make possible to cast the property class to the
    //   internal type --
    operator ValueType()
    {
        assert(m_cObject != NULL);
        assert(Get != NULL);
        return (m_cObject->*Get)();
    }
    friend istream &operator>>( istream  &input, property &d )
    {
        ValueType v;
        input >>v;
        d = v;
        return input;
    }


    friend istream& getline (istream&  is, property& str)
    {
        ValueType v;
        getline(is,v);
        str = v;
        return is;
    }

private:
  Container* m_cObject;  //-- Pointer to the module that
                         //   contains the property --
  void (Container::*Set)(ValueType value);
                         //-- Pointer to set member function --
  ValueType (Container::*Get)();
                         //-- Pointer to get member function --
};

like you see, …

cambalinho 142 Practically a Posting Shark

imgaine that you create a function, 1 parameter must recive another function name. how can i create that parameter?
i have 1 property template class(i think you that), but i'm update it. so, like you know for a property we have 2 functions: getfunctionname and setfunction name. what i need to know is how i can create the parameter for recive the function name

cambalinho 142 Practically a Posting Shark

using templates: how can i do a parameter for accept a function name?

cambalinho 142 Practically a Posting Shark

thanks for all.. thanks

cambalinho 142 Practically a Posting Shark

i thot the comma was in function parameters, but you don't use it.. you use "[N]". that's why i ask;)
is these that i ask for you explain to me;)
but seems obvious. thanks for all

cambalinho 142 Practically a Posting Shark

something that i leraned today hehehe
thanks for all
but me ask 1 thing that i don't(i have read about templates, but the tutorials are so good): the template have 2 parameters, but you transform 'N' in second parameter and you don't use comma. can you explain to me these part, please?

cambalinho 142 Practically a Posting Shark
template <typename T>
void print_array(T arr[])
{

    int length;//for recive the array size

    length=sizeof(arr) / sizeof(arr[0]);


    cout << length << endl;
    for (int i = 0; i < length; i++)
    {
        std::cout << arr[i] << " ";
    }
    std::cout << "\n";
}



int main()
{
    string a[6]={"joana", "João", "Manuel", "Zé", "Ana"};
    int b[5]={20, 30, 40, 2};
    int c[7]={50,2,60,1,30,0,53};
    print_array(b);

    return 0;
}
cambalinho 142 Practically a Posting Shark

thanks but for a numeric type?

cambalinho 142 Practically a Posting Shark

heres the array:
int b[5]={20, 30, 40, 2};

length=sizeof(arr) / sizeof(arr[0]);

why i don't get 5, but 1?

cambalinho 142 Practically a Posting Shark
//arr is the array
int length;//for recive the array size
length=sizeof(arr);//recive the array size
cout <<length;
length=length/sizeof(typeid(arr));//calculate the number of elements
cout << sizeof(typeid(arr));

i'm using these code for calculate the number of elements in array.
sizeof(typeid(arr)) these line is for give the type size, but isn't correct
can anyone advice me?

cambalinho 142 Practically a Posting Shark

that's why i love my new language that i will do it;)

cambalinho 142 Practically a Posting Shark

that's why someone tell me for learn C# lol
thanks for all... thanks

cambalinho 142 Practically a Posting Shark

sorry, when i said properties i mean these format:
object.property=value
;)
and yes i will figure out;)
with templates we can do several things. i have the property code and i update it;)
(see my topics;))
sorry if i bored you and thanks for all

cambalinho 142 Practically a Posting Shark

but the static functions don't accept the normal variables... only static:(
more i hate C++:(
so many evolutions and don't use properties(at least the namespace can help us on these) and events(only Visual Studio, but isn't portable:()
hey... properties and events are OOPL concepts:(

cambalinho 142 Practically a Posting Shark

why if i do these:

class Pessoa2 //static class
{
    string strnome=""; //error
public:
.............

i get these error:
"C:\Users\Joaquim\Documents\CodeBlocks\test2\main.cpp|8|error: invalid use of member 'Pessoa2::strnome' in static member function|"
????

cambalinho 142 Practically a Posting Shark

i belive these is a compiler error:(

static void setNome(string nome)
    {

        if(strnome.length() == 0)
           strnome="ana";
        strnome = nome;//error
        showname();
    }

error message:
"C:\Users\Joaquim\Documents\CodeBlocks\test2\main.cpp|27|undefined reference to `Pessoa2::strnome'|"
i don't understand these error... seems the compiler ignores the 'if':(
these don't make sence:(

cambalinho 142 Practically a Posting Shark
static void setNome(string strnome)
    {
        if(nome.length() == 0) string nome="ana";
        nome=strnome;
           showname();

    }

error message:
"C:\Users\Joaquim\Documents\CodeBlocks\test2\main.cpp|26|undefined reference to `Pessoa2::nome'|"

cambalinho 142 Practically a Posting Shark

better question: how i can test if 1 variable was inicializated?
(i tryied: "if(nome==NULL)" but i get errors:()

cambalinho 142 Practically a Posting Shark

let me ask you something:
can i avoid these line:
string Pessoa2::strnome;
and put it in construtor?

cambalinho 142 Practically a Posting Shark

i'm trying doing a static clas, but i, always get errors... now i have head pain:(

class Pessoa2
{
private:
    static string strnome;
public:
    Pessoa2()
    {
        strnome="ana";
    }

    void setnome(string value)
    {
        strnome=value;
    }
    static string getnome()
    {
       return strnome;
    }
};

just seen these static class, what i'm doing wrong?:(

cambalinho 142 Practically a Posting Shark

for now, i don't go mark resolved;)
(unless i can came back, if i need it????)

cambalinho 142 Practically a Posting Shark

i'm 100% new with these forum:
- i know mark topic resolved;
- is there any tool for give you 'points'\rate?
- or these forum works in diferent way?

cambalinho 142 Practically a Posting Shark

thanks for correct me. thanks.

cambalinho 142 Practically a Posting Shark

sorry we can't do for a variable?
(like my code)
i need 2 variables with same class, but we can change the function cout. why??? i'm trying simulate the events with class

cambalinho 142 Practically a Posting Shark

like these:

test a;
test b;

void a::Show()
{
   cout << "hello a";
}

void b::Show()
{
   cout << "hello b";
}

like you see, i use the var name and not the class name;)
is what i need to do.

cambalinho 142 Practically a Posting Shark

thanks. now i must do anotherthing with these class;)
can i put these lines together with property?

Name.setContainer(this);
    Name.setter(&PropTest::setName);
    Name.getter(&PropTest::getName);


property<PropTest,string,READ_WRITE> Name;

instead these code, i want do:
property<PropTest,string,getName,setName, this, READ_WRITE> Name;
(put all together)

so i think that i must change:

template <typename Container, typename ValueType,typename get, typename set, int nPropType>

right?

and in property construtor:

property()
    {
        m_cObject = this;
        Set = set;
        Get = get;
    }

i'm right?

i'm trying do these:

#include <assert.h>
#include <iostream>
#include <typeinfo>
#include <string>

#define READ_ONLY 1
#define WRITE_ONLY 2
#define READ_WRITE 3

using namespace std;

template <typename Container, typename ValueType, typename getfunction=NULL, typename setfunction=NULL,  int nPropType=3>
class property
{
public:
    property()
    {
        m_cObject = assert(Container);
        Set = setfunction;
        Get = getfunction;
    }

    //-- This to set a pointer to the class that contain the
    //   property --




    void setContainer(Container* cObject)
    {
        m_cObject = cObject;
    }

    //-- Set the set member function that will change the value --
    void setter(void (Container::*pSet)(ValueType value))
    {
        if((nPropType == WRITE_ONLY) || (nPropType == READ_WRITE))
            Set = pSet;
        else
            Set = NULL;
    }

    //-- Set the get member function that will retrieve the value --
    void getter(ValueType (Container::*pGet)())
    {
        if((nPropType == READ_ONLY) || (nPropType == READ_WRITE))
            Get = pGet;
        else
            Get = NULL;
    }

    //-- Overload the '=' sign to set the value using the set
    //   member --
    ValueType operator =(const ValueType& value)
    {
        assert(m_cObject != NULL);
        assert(Set != NULL);
        (m_cObject->*Set)(value);
        return value;
    }


    //-- …
cambalinho 142 Practically a Posting Shark

finally i can use 'getline':

friend istream& getline (istream&  is, property& str)
      {
          ValueType v;
        getline(is,v);

         str = v;
         return is;
      }

how can i change the string header?
(i'm using the GNU)
why??? for overloading operator+ and cout and then i don't need write '(string)';)

cambalinho 142 Practically a Posting Shark

for cout, i must use '(string)', or i get errors(that's why that 'if'). anotherthing: i can't use: 'getline(cin, a.Name) ;', why?

cambalinho 142 Practically a Posting Shark

finally i have the function working:

friend istream &operator>>( istream  &input, property &d )
      {
         ValueType v;

            input >> v;

         d = v;
         return input;
      }

these function works, but not with strings ando know why;)
see these new function:

friend istream &operator>>( istream  &input, property &d )
      {
         ValueType v;
         if (typeid(v).name()== typeid(string).name() )
         {
             input >> (string) v;
         }
         else
         {
            input >> v;
         }
         d = v;
         return input;
      }

like you see i'm trying see if the 'v' is 'string'. but i get several errors in 'input >> (string) v;', why?

cambalinho 142 Practically a Posting Shark

sorry can you, please, give me a nice link for i learn how can i overload the operators?

cambalinho 142 Practically a Posting Shark

and if is a void type, you can't use 'return 0;'. because the void type don't return any value;)

cambalinho 142 Practically a Posting Shark

i build these code. it's very cool:
in test.h:

class test
{
private:
    bool blVisible;
    int x=0,y=0;
public:
    void Show();
    bool Visible()
    {
        return blVisible;
    }
    void Visible(bool value)
    {
        blVisible=value;
        if (value==true) Show();//call the event
    }
};

in main.cpp:

include <iostream>
#include "test.h"

using namespace std;

test a;

void test::Show()//the 'event' procedure
{
    cout << "showed";
}

int main()
{
    //read data

    bool b;
    cin >> b;
    a.Visible(b);
    cin >> b;
    a.Visible(b);
    return 0;
}

these code works fine. but imagine that you have 2 test varables, we get the same cout:(
so, how can i change these line:

void test::Show()//the 'event' procedure

for be used with diferent variables names?
(like these 'void a::Show()')

cambalinho 142 Practically a Posting Shark

thanks to all