about class's and 'events'
in hedear file(.h):
Code:
class test{
private:
bool blVisible;
public:
void Show();
bool Visible()
{
return blVisible;
}
void Visible(bool value)
{
blVisible=value;
if (value==true) Show();//call the event
}
};
and in main.cpp:
Code:
#include <iostream>
#include "test.h"
#include <conio.h>
#include <fstream>
using namespace std;
test a;
void test::Show()
{
cout << "showed";
}
int main()
{
//read data
bool b;
cin >> b;
a.Visible(b);
cin.clear();
cin >> b;
a.Visible(b);
getch();
return 0;
}
just see these 2 lines:
Code:
test a;
void test::Show()
imagine that we do another: 'test c;'
the 'void test::Show()' will be the same and do the same cout:(
how can i work like these:
'void varname::Show()'??
Re: about class's and 'events'
Maybe it's just me, but the question doesn't seem clear. Are you trying to do this?
Test a;
a.Show();
Test b;
b.Show();
If not, can you clarify your question.
Re: about class's and 'events'
I agree with GCDEF that zour question is not clear.
Besides:
Quote:
Originally Posted by
Cambalinho
Code:
class test{
...
void Visible(bool value)
{
blVisible=value;
if (value==true) Show();//call the event
}
};
It is not a good style:
1. to place more than one statement in a line;
2. to compare boolean values with true;
Better style would be:
Code:
class test{
...
void Visible(bool value)
{
blVisible = value;
if (value)
Show();//call the event
}
};
Re: about class's and 'events'
Quote:
Originally Posted by
GCDEF
Maybe it's just me, but the question doesn't seem clear. Are you trying to do this?
Test a;
a.Show();
Test b;
b.Show();
If not, can you clarify your question.
see again the 'correct' main.cpp:
Code:
#include <iostream>
#include "test.h"
#include <conio.h>
#include <fstream>
using namespace std;
test a;
void a::Show()
{
cout << "showed";
}
int main()
{
//read data
bool b;
cin >> b;
a.Visible(b);
cin.clear();
cin >> b;
a.Visible(b);
getch();
return 0;
}
see these:
Code:
test a;
test c;
void a::Show()
{
cout << "showed";
}
void c::Show()
{
cout << "show anotherone";
}
now that sub only works for 'a' and anotherone for 'c'. can i do these?
Re: about class's and 'events'
Quote:
Originally Posted by
Cambalinho
see these:
Code:
test a;
test c;
void a::Show()
{
cout << "showed";
}
void c::Show()
{
cout << "show anotherone";
}
What is a? Is it a class or an instance of class test? :confused:
If former - then what does this linemean?
If latter - then what does this "implementation"
Code:
void a::Show()
{
cout << "showed";
}
mean?
The same question - for c :rolleyes:
Re: about class's and 'events'
Quote:
Originally Posted by
VictorN
What is
a? Is it a
class or an
instance of class test? :confused:
If former - then what does this line
mean?
If latter - then what does this "implementation"
Code:
void a::Show()
{
cout << "showed";
}
mean?
The same question - for
c :rolleyes:
the 1st post;)
ok. i will repeat:
test.h:
Code:
#include <iostream>
class test
{
private:
bool blVisible;
public:
void Show();
bool Visible()
{
return blVisible;
}
void Visible(bool value)
{
blVisible=value;
if (value==true) Show();//call the event
}
};
now in main.cpp:
Code:
#include "test.h"
test a;
test c;
void a::Show()
{
cout << "showed";
}
void c::Show()
{
cout << "show anotherone";
}
int main()
{
//read data
bool b;
cin >> b;
a.Visible(b);
cin.clear();
cin >> b;
a.Visible(b);
getch();
return 0;
}
test is the class name;)
if i use:
these sub will be the same for all variables. that's why i'm asking if i can do these:
so the cout cound be diferent;)
can i do these?
Re: about class's and 'events'
Quote:
Originally Posted by
Cambalinho
the 1st post;)
ok. i will repeat:
Oh, please do NOT do it! Don't repost your fantasies!
Quote:
Originally Posted by
Cambalinho
test is the class name;)
if i use:
these sub will be the same for all variables.
Correct!
Quote:
Originally Posted by
Cambalinho
... that's why i'm asking if i can do these:
so the cout cound be diferent;)
can i do these?
No.
But you could derive a bew class(es) from test and overload or override this method in there.
Re: about class's and 'events'
Quote:
Originally Posted by
VictorN
Oh, please do NOT do it! Don't repost your fantasies!
Correct!
No.
But you could derive a bew class(es) from test and overload or override this method in there.
how can i do it?
(you can give me a link for learn, please?)
Re: about class's and 'events'
If you do NOT know the basic of C++ then why do you ask it here in the Forum?
First read books, tutorials, blogs for the beginners. Test examples...
As for the link - Google is your friend.
And note that CG-Forum in not a grade school!
Re: about class's and 'events'
Quote:
Originally Posted by
VictorN
If you do NOT know the basic of C++ then why do you ask it here in the Forum?
First read books, tutorials, blogs for the beginners. Test examples...
As for the link - Google is your friend.
And note that CG-Forum in not a grade school!
i know overload, what i don't is how i can do what you sugest:(
Re: about class's and 'events'
Quote:
Originally Posted by
Cambalinho
i know overload, what i don't is how i can do what you sugest:(
Are you kidding? :confused: :(
Re: about class's and 'events'
Quote:
Originally Posted by
Cambalinho
i know overload, what i don't is how i can do what you sugest:(
No matter how many times you repeat it, your code makes no sense, therefore your question makes no sense. Look at what I posted earlier. If that's now what you're trying to do, explain using words, not code, exactly what you're trying to do.
Re: about class's and 'events'
Quote:
Originally Posted by
GCDEF
No matter how many times you repeat it, your code makes no sense, therefore your question makes no sense. Look at what I posted earlier. If that's now what you're trying to do, explain using words, not code, exactly what you're trying to do.
:( sorry something:(
what i'm trying to do is events with class's. thats why i use variables class for use that function.
sorry my english:( sorry for something:(
but i understand that i need learn much more about C++. i'm relearn it. sorry VictorN, but i'm not kidding with you. i understand the forum isn't a school, but the book don't bring all:(
sorry something:(
Re: about class's and 'events'
This is an example
Code:
#include <iostream>
using namespace std;
class c1 {
public:
virtual void show();
};
class c2 : public c1 {
public:
virtual void show();
};
void c1::show()
{
cout << "show in c1" << endl;
}
void c2::show()
{
cout << "show in c2" << endl;
}
void cshow(c1& c)
{
c.show();
}
int main()
{
c1 i1;
c2 i2;
cshow(i1);
cshow(i2);
return 0;
}
It produces the output
Code:
show in c1
show in c2
This is basic c++ class stuff. Study the book you're got!
Re: about class's and 'events'
Quote:
Originally Posted by
2kaud
This is an example
Code:
#include <iostream>
using namespace std;
class c1 {
public:
virtual void show();
};
class c2 : public c1 {
public:
virtual void show();
};
void c1::show()
{
cout << "show in c1" << endl;
}
void c2::show()
{
cout << "show in c2" << endl;
}
void cshow(c1& c)
{
c.show();
}
int main()
{
c1 i1;
c2 i2;
cshow(i1);
cshow(i2);
return 0;
}
It produces the output
Code:
show in c1
show in c2
This is basic c++ class stuff. Study the book you're got!
so i must use virtual functions. thanks for all to all
realy thanks.