-
Your name data member is of type string, so in order for this to all work either:
1) The header needs to #include the string header, or...
2) Any source file that #includes this class header must also #include the string header before it #includes the class header.
You also need to be mindful of any namespace issues as well.
Maybe:
Code:
#include <string>
class Player
{
double points,value;
std::string name, pos;
public:
Player (std::string,std::string,double);
};
-
You also need header include guards. You also need more code in main to create variables named name, pos and ppoints. hk_mp5kpdw's code was an example, not meant to be used directly with your class and compiled immediately. You ahve more work to do.
-
I don't know what header guards are but I'm close...The variables are all defined in my main
class. I'm gettin an error error C2664: 'Player::Player(std::string,std::string,double)' : cannot convert parameter 3 from 'std::string' to 'double'
Player.cpp
Code:
#include <iostream>
#include <string>
#include "Player.h"
using namespace std;
Player::Player (string n, string p, double pts)
{
name = n;
pos = p;
points = pts;
}
Player.h
Code:
#include <string>
using namespace std;
class Player
{
double points,value;
string name, pos;
public:
Player (string,string,double);
};
main
Code:
Player a(name, pos, ppoints);
-
that was a dumb error, nvm working now, i'll be back when it breaks again
-
>> I'm gettin an error error C2664
Apparently ppoints is a string variable, but you should be passing a double.
>> I don't know what header guards are but I'm close.
Look them up. You will need them to get this program working.
-
How do you properly provide implementation. Apparently this is wrong haha
Code:
#include <iostream>
#include <string>
#include "Player.h"
using namespace std;
Player::Player (string n, string p, double pts)
{
name = n;
pos = p;
points = pts;
}
Player::void calcPoints()
{
value = 10;
}
Player::double getPoints()
{
return value;
}
-
Code:
#include <iostream>
#include <string>
#include "Player.h"
using namespace std;
Player::Player (string n, string p, double pts)
{
name = n;
pos = p;
points = pts;
}
void Player::calcPoints()
{
value = 10;
}
double Player::getPoints()
{
return value;
}
-
ah sweet, ok, one(two) more errors. It says I need a class/struct/union
Code:
int main ()
{
PlayerIO a();
a.makeFile();
a.makePlayerList();
return 0;
}
-
Include guards is when you have a mechanism to prevent the same header-file having it's content included multiple times - most of the time, once is perfectly fine.
Example: myclass.h
Code:
#ifndef __MYCLASS_H__
#define __MYCLASS_H__
class myclass {
....
}
...
...
...
#endif
It is good practice to ALWAYS do this for ALL header-files, because somtimes (in larger projects) header-files are included by other header files. Let's say we have a "baseclass" that, that is then needed by classA and classB, and in our "main.c", we need both classA and classB, we want to include both "classA.h" and "classB.h". At the same time, we may not want to tell everyone using "classA" that they need to FIRST include "baseclass.h". So we add "baseclass.h" to both "classA.h" and "classB.h" - but without guarding against multiple includes, the content of "baseclass" would now be twice in the same compile - that's generally a bad idea. This is where include-guards are needed.
--
Mats
-
Note that identifiers with double underscores are reserved for the implementation, so it is best to not use them in your include guards. MYCLASS_H would be better.
>> It says I need a class/struct/union
What is PlayerIO? You have a class called Player, but the compiler doesn't recognize PlayerIO. Don't forget to post the entire text of the error message(s) to make it easier for us to help. Also, don't put empty prentheses after the variable when declaring it, the compiler will think it is a function declaration.
-
It is a function declaration...Error 1 error C2228: left of '.makeFile' must have class/struct/union c:\Documents and Settings\chyron\Desktop\jp\TestApp\TestApp\TestApp .cpp 10
I do have a PlayerIO class, I just made it. It has a function makeFile
-
And do you include the correct headerfile? Do you use the correct spelling everywhere?
--
Mats
-
yes, this is my main class. Its very short. I included both of the headers. They both exist
Code:
#include <string>
#include "Player.h"
#include "PlayerIO.h"
using namespace std;
int main ()
{
PlayerIO a();
a.makeFile();
a.makePlayerList();
return 0;
}
-
Didn't DaveD say something like "Don't put parenthesis behind the variable name, the compiler will think it's a function"? I clearly seem to remember that. Read your code again...
--
Mats
-
>> Didn't DaveD say something like "Don't put parenthesis behind the variable name, the compiler will think it's a function"?
I added that as an edit, sorry if it was too late to be seen.