Anyone to fix this??

//example of constructor
#include <iostream>
#include <string>
#include "simple.h"

class Simple{
string Mystring("This is what am testing");
public:
Simple ();
void const (string)
{
return Mystring;
}

};

Simple::Simple (string a) {
Mystring = a;
Cout << a ;
}

int main () {
//declaring objects
Simple a;
Simple ();
system("pause");
return 0;
}
There are so many errors with this that I can't even tell what it is you're trying to do.

Can you explain what you're going for?
what is inside simple.h??
Just corrected some of the errors. simple.h is commeted. Am trying to pass the string: This is what am testing.
/example of constructor
#include <iostream>
#include <string>
//#include "simple.h"

class Simple{
string Mystring("This is what am testing");
public:
Simple ();
void const (string)
{
return Mystring;
}

};

Simple::Simple (string a) {
Mystring = a;
}

int main () {
//declaring objects
Simple a;
Simple ();
system("pause");
return 0;
}
where are you trying to pass the string to?
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
#include <iostream>
#include <string>
using namespace std;

class Simple
{
	string Mystring;//("This is what am testing");

	public:
		Simple ();

		Simple::Simple (string a) 
		{
			Mystring = a;
		}

		string getString()
		{
			return Mystring;
		}

};

int main () 
{
	//declaring objects
	Simple a;
	Simple ();
	system("pause");
	return 0;
}
if u want to use string..
u should using namespace too..
then there are no const void..
const is only for a variable..

more over..
im not make ur program to work..
just correct the program as u ask..
u still needed to find a way to pass the text to mystring..
This is where I am now,
ERROR: simple.cpp prototype for `Simple::Simple(std::string)' does not match any in class `Simple'

// created by William Mbeera
#include <iostream>
#include <string>
using namespace std;

class Simple
{
string Mystring;

public:
Simple ();
string getString();
};

Simple::Simple (string a)
{
Mystring = a;
}

Simple::getString()
{
return Mystring;
}

int main ()
{
//declaring objects
Simple a("This is what am testing");

Simple ();
system("pause");
return 0;
}
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
33
34
#include <iostream>
#include <string>
using namespace std;

class Simple
{
	string Mystring;
	public:

	Simple ();
	Simple (string a);
	string getString(); 
};

Simple::Simple (string a) 
{
	Mystring = a;
}

string Simple::getString()
{
	return Mystring;
}


int main () 
{
//declaring objects
	Simple a("This is what am testing");

	system("pause");
	return 0;
}


u're so close..gud luck bro..
Something am not seeing.
#include <iostream>
#include <string>
using namespace std;

class Simple
{
string Mystring;
public:

Simple ();
Simple (string a);
string getString();
};

Simple::Simple (string a)
{
Mystring = a;
}

string Simple::getString()
{
return Mystring;
}


int main ()
{
string text("This is what am testing");
//declaring objects
Simple a;
a.getString();

system("pause");
return 0;
}
Sorry some mistake.

ERROR: 31 text.cpp no matching function for call to `Simple::getString(std::string&)'

#include <iostream>
#include <string>
using namespace std;

class Simple
{
string Mystring;
public:

Simple ();
Simple (string a);
string getString();
};

Simple::Simple (string a)
{
Mystring = a;
}

string Simple::getString()
{
return Mystring;
}


int main ()
{
string text("This is what am testing");
//declaring objects
Simple a;
a.getString(text);

system("pause");
return 0;
}
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
33
34
35
#include <iostream>
#include <string>
using namespace std;

class Simple
{
	string Mystring;
	public:

	Simple ();
	Simple (string a);
	string getString(); 
};

Simple::Simple (string a) 
{
	Mystring = a;
}

string Simple::getString()
{
	return Mystring;
}


int main () 
{
	string text("This is what am testing");
	//declaring objects
	Simple a(text);
	string something = a.getString();

	system("pause");
	return 0;
}
may be u want to do this..

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
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
using namespace std;

class Simple
{
	string Mystring;
	public:

	Simple ();
	Simple (string a);
	string getString(); 
	void setText(string a);
};

Simple::Simple (string a) 
{
	Mystring = a;
}

void Simple::setText(string a)
{
	Mystring = a;
}

string Simple::getString()
{
	return Mystring;
}


int main () 
{
	string text("This is what am testing");
	//declaring objects
	Simple a;
	a.setText(text);
	string something = a.getString();

	system("pause");
	return 0;
}

It looks perfect but returns an error:


[Linker error] undefined reference to `Simple::Simple()'
closed account (1yR4jE8b)
In that code there is a declaration for a no argument constructor for the Simple class, but there is no code to implement it. Hence the "undefined reference" error.
Topic archived. No new replies allowed.