-2
project1.cppC++オブジェクト指向プログラミング
#include "stdafx.h"
#include "Bicycle.cpp"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
bool runP = true;
do {
Bicycle object();
char oType;
cout << "Would you like a (B)icycle, or (A)nimal? E for Exit\n";
cin >> oType;
if (oType == 'B' || oType == 'b') {
int seat, wheels;
string brand;
cout << "How many wheels does the bike have?\n";
cin >> wheels;
object().setWheels(wheels);
cout << "How many seats does the bike have?\n";
cin >> seat;
object().setSeats(seat);
cout << "What is the brand of the bike?\n";
cin >> brand;
object().setBrand(brand);
object().toString();
} else if (oType == 'A' || oType == 'a') {
} else if (oType == 'e' || oType == 'E') {
runP = false;
}
} while (runP == true);
return 0;
}
Bicycle.h
#include <string>
class Bicycle {
private:
int wheels;
int seats;
std::string brand;
public:
Bicycle();
Bicycle(int w, int s, std::string b);
int getWheels();
int getSeats();
std::string getBrand();
void setWheels(int w);
void setSeats(int s);
void setBrand(std::string b);
void toString();
};
Bicycle.cpp
#include "stdafx.h"
#include "Bicycle.h"
#include <string>
Bicycle::Bicycle() {
}
Bicycle::Bicycle(int w, int s, std::string b) {
}
int Bicycle::getWheels() {
return wheels;
}
int Bicycle::getSeats() {
return seats;
}
std::string Bicycle::getBrand() {
return brand;
}
void Bicycle::setWheels(int w) {
wheels = w;
}
void Bicycle::setSeats(int s) {
seats = s;
}
void Bicycle::setBrand(std::string b) {
brand = b;
}
void Bicycle::toString(){
std::cout << "Bike object has: Brand: " << getBrand() << ", wheels: " << getWheels() << ", seats: " << getSeats() << "\n";
}
stdaf x.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
エラー:
1>------ Build started: Project: project1, Configuration: Debug Win32 ------
1> stdafx.cpp
1> Bicycle.cpp
1> Generating Code...
1> Compiling...
1> project1.cpp
1> Generating Code...
1> Skipping... (no relevant changes detected)
1> Window.cpp
1> Animal.cpp
1>project1.obj : error LNK2005: "public: __thiscall Bicycle::Bicycle(void)" ([email protected]@[email protected]) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: __thiscall Bicycle::Bicycle(int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: int __thiscall Bicycle::getWheels(void)" ([email protected]@@QAEHXZ) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: int __thiscall Bicycle::getSeats(void)" ([email protected]@@QAEHXZ) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Bicycle::getBrand(void)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: void __thiscall Bicycle::setWheels(int)" ([email protected]@@[email protected]) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: void __thiscall Bicycle::setSeats(int)" ([email protected]@@[email protected]) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: void __thiscall Bicycle::setBrand(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) already defined in Bicycle.obj
1>project1.obj : error LNK2005: "public: void __thiscall Bicycle::toString(void)" ([email protected]@@QAEXXZ) already defined in Bicycle.obj
1>project1.obj : error LNK2019: unresolved external symbol "class Bicycle __cdecl object(void)" ([email protected]@[email protected]@XZ) referenced in function _wmain
1>C:\Users\Hash\Documents\Visual Studio 2010\Projects\project1\Debug\project1.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
どこがあなたの質問ですか? –
一般的に、人々は彼らが問題の解決に努力し、彼らが試したことを列挙していることを示しています。それ以外の場合は、何も解決しようとしなかったという前提で、コード/エラーをコピーしてWebフォームに貼り付け、提出するだけです。 –
ちょうど、本当の自転車のsetWheelsはどうですか? –