I create an object of the ring class named userRing. The user then proceeds to set the wire thickness and the innerdiameter and then the material. When I use the std::string type for the functions and class members, Visual Studio 2010 B2 gives me a shitload of errors. Why is this wrong?
main.cpp
[cpp]
#include "ring.h"
#include <iostream>
int main()
{
ring smallRing;
//ring medRing;
//ring bigRing;
ring userRing;
smallRing.innerDiam = 6;
smallRing.wireThick = 1.3;
smallRing.material = "Feathersteel";
/*medRing.innerDiam = 8;
medRing.wireThick = 1.3;
bigRing.innerDiam = 11;
bigRing.wireThick = 1.3;
std::cout << smallRing.aspectR() << "\t" <<
medRing.aspectR() << "\t" << bigRing.aspectR();
std::cout << "Input inner diameter:\t";
std::cin >> userRing.innerDiam;
std::cout << "\n" << "Input wire thickness:\t";
std::cin >> userRing.wireThick;
std::cout << "\n" << userRing.aspectR() << "\n";
*/
std::cout << smallRing.getMaterial() << "\n";
std::cin.ignore();
std::cin.get();
return 0;
}
[/cpp]
ring.h
[cpp]
#pragma once
#include <iostream>
class ring
{
public:
double innerDiam;
double wireThick;
/*STRINGTYPE*/std::string material;
double aspectR();
/*STRINGTYPE*/std::string getMaterial();
};
double ring::aspectR()
{
return innerDiam / wireThick;
}
/*STRINGTYPE*/std::string ring::getMaterial()
{
return material;
}
[/cpp]
Should we use our mind powers to guess the errors?
The only thing I'm seeing in 10 seconds of looking is that you're not including <string> in ring.h
Holy shit. How could I've missed that?
Thanks.
If it were up to me, I'd return a char*
[QUOTE=turby;18893117]If it were up to me, I'd return a char*[/QUOTE]
Why would he use a pointer? Why would he make it mutable?
Why use a char*?
It's not like "If it were up to me" says anything about your reasoning.
[QUOTE=turby;18893117]If it were up to me, I'd return a char*[/QUOTE]
don't troll
Sorry, you need to Log In to post a reply to this thread.