I've got the problem with following code. It should get the object parameters from the txt file. Of course to get enum values correctly I've made this simple getline() function. I'm keep getting errors which I've tried to repair, but I still have no idea what's wrong. VC says that 'no instance of overloaded function getline matches the argument list'.
My code:
CKomputer.cpp
#include <iostream>
#include <cstdio>
#include <string>
#include <fstream>
#include "CKomputer.h"
#include "Procesor.h"
#include "KartaDzwiekowa.h"
#define TESTPR1
using namespace std;
void Komputer::pobierz(string nazwa)
{
#ifdef TESTPR1
cout<<"Uruchomiono metode pobrania stanu obiektu Komputer z pliku"<<endl;
#endif
ifstream plik_wejsciowy;
plik_wejsciowy.open(nazwa+".txt");
int zastos;
getline(plik_wejsciowy,linia);
zastos=atoi(linia.c_str());
zastosowanie=Komputer::zastosowanie(zastos);
plik_wejsciowy >> nazwa_komputera >> ram >> ile_kart_dzwiekowych >> zastos;
procesor.wczytaj(plik_wejsciowy);
if (ile_kart_dzwiekowych>0)
{
for (int i=0;i<ile_kart_dzwiekowych;i++)
karta_dzwiekowa[i].wczytaj(plik_wejsciowy);
}
plik_wejsciowy.close();
}
CKomputer.h
#pragma once
#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
#include "UrzadzenieElektroniczne.h"
#include "Procesor.h"
#include "KartaDzwiekowa.h"
using namespace std;
enum zastosowanie{biznes, gaming, grafika, programowanie};
class Komputer: public UrzadzenieElektroniczne
{
private:
Procesor procesor;
KartaDzwiekowa *karta_dzwiekowa;
protected:
string nazwa_komputera;
int ram;
int ile_kart_dzwiekowych;
public:
Komputer();
Komputer(string nazwa_komputera2, int ram2, int ile_kart_dzwiekowych2);
Komputer(const Komputer& k);
Komputer(int ilosc_kart);
~Komputer();
static int ile_Komputerow;
static int licz_ile_Komputerow();
void komp_info();
void wlaczenieurz();
void zapisz(string nazwa);
void pobierz(string nazwa);
zastosowanie zastos;
};
Related
I'm new to c++ and was having problem with doing some inheritance, does any one know why im getting this error? (its the only error I'm getting when compiling).
I compiled with g++ -o. Also I'm so sorry in advance if I'm doing a lot of things wrong here, I'm very new to c++. >_<
Please let me know how I can make my code better or more efficient.
computer.h
#ifndef RPS_H
#define RPS_H
#include <iostream>
#include <string>
#include <stdio.h>
class Computer
{
public:
Computer(std::string);
~Computer();
char charc;
};
#endif
human.h
#ifndef HUMAN_H
#define HUMAN_H
#include <iostream>
#include <string>
#include <stdio.h>
class Human
{
public:
Human(std::string);
~Human();
char charh;
};
#endif
referee.h
#ifndef REFEREE_H
#define REFEREE_H
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
class Referee : public Human{
public:
Referee();
~Referee();
bool Winneris();
};
#endif
Computer.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "computer.h"
using namespace std;
Computer::Computer(string char_c)
{
}
Computer::~Computer()
{
}
Human.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
using namespace std;
Human::Human(string char_h){
char_h=charh;
cout<<"r/p/s?"<<endl;
cin>>charh;
}
Human::~Human()
{
}
Referee.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "referee.h"
using namespace std;
Referee::Referee(){
}
bool Referee::Winneris(){
if (charh=='r'){
cout<<"draw"<<endl;
}
else if(charh=='p'){
cout<<"Victory!"<<endl;
}
else if(charh=='s')
{
cout<<"Defeat"<<endl;
}
return 0;
}
Referee::~ReReferee(){
}
main.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "human.h"
#include "computer.h"
#include "referee.h"
using namespace std;
string char_h;
string char_c;
// main program
int main()
{
Human *round1h;
round1h = new Human(char_h);
Computer *round1c;
round1c = new Computer(char_c);
Referee *round1r;
round1r = new Referee();
round1r -> Winneris();
}
When you have written the parameterized constructor in respective classes. You have created the class objects, which call the default constructor which takes no parameter.
You have to define the default constructor as well in your respective classes.
Human::Human()
{}
Computer::Computer()
{}
Referee::Referee()
{}
Constructor types
I keep getting this error and I am not sure why. I get the error posted in the question title. If I take the semicolon out of the class line I get expected semicolon after class.
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctime>
#ifndef die_h
#define die_h
using namespace std;
class Dice;
{
private:
int sides;
int value;
public:
Dice(int=6);
void cast();
int getSides();
int getvalue();
return 0;
}
#endif
How I can sent string variable into function in other file?
main.cpp:
#include <iostream>
#include <conio.h>
#include <string>
#include "headers.hpp"
using namespace std;
int main()
{
string a;
cout<<"Type:"<<endl;
cin>>a;
other(a);
getch();
return( 0 );
}
headers.hpp:
#ifndef HEADERS_HPP
#define HEADERS_HPP
void other(string a);
#endif
function.cpp:
#include "headers.hpp"
#include <iostream>
#include <math.h>
using namespace std;
void other(string a){
cout<<a;}
I don't know why it doesn't work. Do you know solution?
If you are saying it does not compile, you have to move the #include <string> from main.cpp into headers.hpp
I got an error of C:\temp\hashTableProject\main.cpp|14|undefined reference to hash::Hash(std::string)
Anyone know how to solve this problem?
hash.h
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#ifndef HASH_H
#define HASH_H
class hash{
public:
int Hash(string key);
};
#endif // HASH_H
hash.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "hash.h"
using namespace std;
int hash::Hash(string key){
//int hash = 0;
int index;
index = key.length();
return index;
}
main.cpp
#include <iostream>
#include <cstdlib>
#include <string>
#include "hash.h"
using namespace std;
int main()
{
int index;
hash hashOb;
string traget = "Testing";
index = hashOb.Hash(traget);
cout << index << endl;
return 0;
}
Im using CodeBlock 13.12
There is only main.o file in obj folder. I dont know why the hash.o isn't there.
hash is an inbuilt template in "std" namespace.
Try removing using namespace std; lien and use namespace name as and when required.
I have a class called pos... I am trying to poll a method from this class. I used pthread_create(pthread_t thread, pos::Pirnt_data,this);
I get an error that pos is not declared in the scope... I included the h file of pos but I don't understand. I think I am using a wrong format can somebody help me
#include "position.h"
#include "pthread.h"
#include "pos.h"
void position::tick(schedflags_t flags)
{
if(pthread_create(&thread,NULL,pos::Print_data,this)!=0) {
stringstream bad;
bad << "OPIMex: Could not create listener thread: "
}
this class position has method tick that runs every 1 second with the data. I am trying to poll a method Print data from the class pos but it gave me that error any ideas why ?
this is class pos.h
#ifndef POS_H_
#define POS_H_
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <gps.h>
#include <string.h>
#include <pthread.h>
#include <string>
#include <vector>
#include <strings.h>
#include <math.h>
using namespace std;
namespace herpderp {
namespace modules {
int UBX_step =0;
long data;
int UBX_class;
int UBX_id=0;
int UBX_payload_length_hi;
int UBX_payload_length_lo;
int UBX_payload_counter =0;
int ck_a;
int ck_b;
int GPS_timer;
int fd;
unsigned int UBX_buffer[35];
int payload_data;
long lat=0;
long lon=0;
long alt_MSL=0;
long iTOW=0;
long alt=0;
unsigned long LastMS;
int UBX_Read;
vector <float> v;
fstream myfile;
int Open_port(void);
int read_tofile();
long join_4_bytes( unsigned int Buffer[]);
void parse_ubx_gps(void);
void checksum(char ubx_data);
void Print_data();
int push_data_into_vector();
int decode_gps();
int Configure_gps();
int test();
int Close_NEMA();
int Open_UBX();
}
}
#endif //POS_H_
pthread_kill is not on pthread.. It is on signal.h
#include <signal.h>
1) you can provide some code snippet/additional information to help you better.
2) If you are getting linkage error, check if you have linked with -lpthread library.
Form the pos.h it seems that there is no class called pos and you just need to call the function name:
if(pthread_create(&thread,NULL,Print_data,this)!=0) {