Mar 29, 2010 at 12:39am UTC
//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;
}
Mar 29, 2010 at 1:11am UTC
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?
Mar 29, 2010 at 1:12am UTC
what is inside simple.h??
Mar 29, 2010 at 1:21am UTC
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;
}
Mar 29, 2010 at 1:28am UTC
where are you trying to pass the string to?
Mar 29, 2010 at 1:59am UTC
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..
Mar 29, 2010 at 2:20am UTC
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;
}
Mar 29, 2010 at 3:40am UTC
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;
}
Mar 29, 2010 at 3:41am UTC
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;
}
Mar 29, 2010 at 7:33pm UTC
It looks perfect but returns an error:
[Linker error] undefined reference to `Simple::Simple()'
Mar 29, 2010 at 7:59pm UTC
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.