Penn wrote:
Hello, I'm new to C++ and while I was playing around with one of my
ideas I stumbled uppon the error message I used as a subject for this
topic.
My question to you out there is how can i make this part of the code
work :
class PwCheck
{
public:
string x;
cout<< "Type in the Pw:\t" <<endl;
cin>> x;
cin.ignore();
Thank you in advance for any helpfull answers.
C++ is not dynamic language
it would be ok in Python
class X:
.... print "constructing X class"
.... def __init__(self):
.... print "constructing instance from X"
....
constructing X class x = X()
constructing instance from X
it would be ok in Ruby
irb(main):097:0* class X
irb(main):098:1> puts "constructing class X"
irb(main):099:1> def initialize
irb(main):100:2> puts "constructing instance from X"
irb(main):101:2> end
irb(main):102:1> end
constructing class X
=> nil
irb(main):103:0> x = X.new
constructing instance from X
=> #<X:0x402126bc>
irb(main):104:0>
but in C++ things inside a class are not "executable" as compiler sees
them (well methaprogaming with templates excluded)
all you can put in a class is objects and methods
and each can be one of public, protected and private
it affects its visibility and accessability
so simple class would look like
class X
{
public:
void run();
int x;
private:
void doit() { // here you can add you cout }
int y;
}; // << don't forget ;
void X::run()
{
// here you should add you code ...
std::cout << "print me" << std::endl;
}
hth, Daniel