trouble grasping constructing and overall use of class

Dec 5, 2011 at 10:29pm
having trouble with the concepts of writing constructors and objects.

here is my code, very basic but there are red lines beneath the word after the ::

if anyone could help, it'd be greatly appreciated. I read the books, copied their format, but it doesnt work for me.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// newproject2.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <fstream>
#include <string>
#include <math.h>

using namespace std;

class newUser{
public:
	newUser();
	string name;
	string password;
	
};

newUser::newUser{
	cout<<"Welcome to the New User Menu!:"<<endl;
};

string newUser::name{
	cout<<"please enter new user name:"<<endl;
	cin>>name;
};

string newUser::password{
	cout<<"Please enter password:"<<endl;
	cin>>password;
};
Dec 5, 2011 at 10:33pm
name and passwords are member variables and not functions so you can't give them code like that.
Dec 5, 2011 at 10:35pm
what would be good way to code it? i'm trying to have a menu to create a username and password. i just don't really understand it....
Dec 5, 2011 at 10:38pm
even when i user the constructor newuUser::newUser it doesnt work and thats how the manual said to create a constructor.
Dec 5, 2011 at 10:39pm
line 19 newUser::newUser(){
Dec 5, 2011 at 10:42pm
it says declaration is incompatible and looks like a function but has no parameters
Dec 5, 2011 at 10:43pm
i got it, turns out the() was needed. thanks!
Topic archived. No new replies allowed.