|
you can use any communication protocol UDP or TCP.
|
|
|
|
|
Hello,
I want to create a game that uses graphics (I will be coding in C++).
Though I am uncertain of which graphics library to use or the how to involve images.
My end goal is to be create a 3D game - but I suppose it is better to learn step by step. So I want to create a 2D graphic interface game and then build up from there.
Does anyone have any suggestions for which might be the best graphics library to use?
With Kind Regards,
Live Support Software for Business
April
Comm100 - Leading Live Chat Software Provider
|
|
|
|
|
|
Will do - thank you Mr. MacCutchan.
Live Support Software for Business
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:40am.
|
|
|
|
|
#include <iostream>
using namespace std;
template <class T> class Array {
public:
friend ostream& operator<< (ostream&, Array<T>&);
private:
T *pType;
};
template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
output << "output array" << endl;
return output;
}
ostream& operator<< (ostream&, Array<int>&);
int main()
{
Array<int> theArray;
cout << theArray << endl;
return 0;
}
I tried compiling the following code and I get a warning on line 5 that this statement declares a non-template function but despite this warning the code does compile. However, it does not link. The error message from the linker is:
/tmp/ccIbnsNk.o:t2.C text+0x9b): undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char=""> >&, Array<int>&)'
I feel the above code defines the function the linker says is undefined. What am I missing?
Bob
|
|
|
|
|
This line:
ostream& operator<< (ostream&, Array<int>&);
declares a new function that takes an Array<int> as an argument, but you haven't provided a function body which leads to the linker error.
If you meant to explicitly instantiate the template for int, you need a bit more:
template ostream& operator<< (ostream&, Array<int>&);
|
|
|
|
|
Thanks for the response. However, I added the line you suggested and it did not solve the problem. I believe the line you suggested tells the compiler that we want to specialize the implementation for the special case of int. However, I am not sure of my facts on this one.
Bob
|
|
|
|
|
Sorry, I missed out that you have to fix the friend declaration too:
template<T>
friend ostream& operator<< (ostream&, Array<T>&);
An explicit specialization would look like this:
template<>
ostream& operator<< (ostream& output, Array<int>& theArray)
{
output << "output int array" << endl;
return output;
}
|
|
|
|
|
error message
.cpp(44): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
Header File :
#ifndef RESERVATION_H_ //to avoid redefinition errors
#define RESERVATION_H_
#include <iostream>
#include <string>
#include "Passenger.h"
using namespace std;
class Reservation{
private:
static int sn;
const string ID;
bool smokerSeat;
Passenger passenger;
public:
Reservation(string psngrName, long psngrPhone, string psngrPassport, bool smoke);
Reservation(Passenger& psngr, bool smoke);
Passenger getPassenger();
bool isSmoker();
string getReservationNumber();
void printDetails();
string ID_sn();
};
#endif /*RESERVATION_H_*/
source File
#include <string>
#include <iostream>
#include <sstream>
#include "reservation.h"
using namespace std;
Reservation::Reservation(string psngrName, long psngrPhone, string psngrPassport, bool smoke)
:ID(psngrName)
{
passenger.setPassengerName(psngrName);
passenger.setContactNumber(psngrPhone);
passenger.setPassportNumber(psngrPassport);
smokerSeat=smoke;
}
Reservation::Reservation(Passenger& psngr, bool smoke)
{
passenger.setPassengerName(psngr.getPassengerName());
passenger.setPassportNumber(psngr.getPassportNumber());
passenger.setContactNumber(psngr.getContactNumber());
smokerSeat=smoke;
}
Passenger Reservation::getPassenger()
{
return this->passenger;
}
bool Reservation::isSmoker()
{
return smokerSeat;
}
void Reservation::printDetails()
{
cout<< "passenger name: "<<passenger.getPassengerName();
cout<<"passenger Contact Number:"<<passenger.getContactNumber();
cout<<"Passenger Passport Number :"<<passenger.getPassportNumber();
cout<<"passenger ID:"<<Reservation::getReservationNumber();
cout<<" smoking preferences: "<<(isSmoker()?"smoker":"nonsmoker");
}
i got this problem in the reservation.cpp
i cant change any thing in the header file all what i can change is on the cpp file
can any one help to solve this problem
this is line 44:
ID=ss.substr(0,2)+s;
and in header file i have
string ID_sn();
function but im really confused how can i use it int the implementation file (source)
|
|
|
|
|
What line is line 44 ?
Nihil obstat
|
|
|
|
|
this one
ID=ss.substr(0,2)+s;
|
|
|
|
|
On line 44, you can not assign anything to the "const string ID". Are you sure the assingment isn't supposed to be ID_sn instead as it is public and not a const?
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
i change it to this
ID_sn()=ss.substr(0,2)+s;
and the previous error solved
BUT i got another error :
1>Reservation.obj : error LNK2019: unresolved external symbol "public: __thiscall Passenger::Passenger(void)" (??0Passenger@@QAE@XZ) referenced in function "public: __thiscall Reservation::Reservation(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >,long,class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >,bool)" (??0Reservation@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@J0_N@Z)
|
|
|
|
|
You are missing a Passenger ctor in your cpp file that is used by one of your Reservation ctors.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
can you help me how can i add the passenger constructor in the cpp file
this is the passenger constructor :
#include <iostream>
#include "Passenger.h"
using namespace std;
Passenger::Passenger(string a="",string b="",long c=0)
{
setPassengerName(a);
setPassportNumber(b);
setContactNumber(c);
}
many thanks
|
|
|
|
|
Try this.
Passenger::Passenger()
{
}
This ctor for Passenger is used by the Reservation class.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
its WORK
but it seems i will have infinite No. of errors
when i got the last error i got another LNK2019 error with it, but i thought if i solve one of them the other will be solved also , and my thoughts was wrong
this is the other error :
1>Reservation.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __thiscall Reservation::ID_sn(void)" (?ID_sn@Reservation@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "public: class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __thiscall Reservation::getReservationNumber(void)" (?getReservationNumber@Reservation@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
|
|
|
|
|
This time you get the error because you didn't define the funtion ID_sn().
I would just create a local std::string, assign to that one in line 44 and return it at the end.
|
|
|
|
|
You defined ID as const .
Also your <pre> tags are being ignored, have a look at the setting of the Treat my content as plain text, not as HTML checkbox, at the bottom of this page and/or in your settings page.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
i cant change anything in the header file
all my work will be on the source file only
|
|
|
|
|
Hi everyone
I have three questions
1.why do I need to use of TEXT macro in my codes and if I remove it compiler shows error
2.why CreateProcess cant open test.txt while second parameter is command line and I have to write full path ("c:\\notepad.exe c:\\1.txt")
3.Do I need to use of WaitForSingleObject
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof (STARTUPINFO);
GetStartupInfo (&si);
si.dwFlags = STARTF_USESHOWWINDOW |STARTF_TITLEISAPPID ;
si.wShowWindow = SW_SHOWMAXIMIZED;
si.lpTitle=TEXT("Test");
if(CreateProcess(TEXT("c:\\notepad.exe"),TEXT("c:\\test.txt"),NULL,
NULL,FALSE,NULL,NULL,NULL,&si,&pi))
{
//WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
Thanks
|
|
|
|
|
messages wrote: 1.why do I need to use of TEXT macro in my codes and if I remove it compiler shows error See here.
messages wrote: 2.why CreateProcess cant open test.txt while second parameter is command line and I have to write full path ("c:\\notepad.exe c:\\1.txt") Do you understand the difference between absolute vs. relative paths?
messages wrote: 3.Do I need to use of WaitForSingleObject Only if you need to wait.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Do you know your answers are great?
Thanks
|
|
|
|
|
Hi
I have to program, one is in c++ I have compiled with VStudio 2010, and one in c compiled in gcc.
In c program, I need data which come from c++.
how to export data from c++ to C? does any one have the sample code for this one?
thankyou
|
|
|
|
|
Data is data, it has nothing to do with what language is used to process it. Please try and explain your problem in more detail.
One of these days I'm going to think of a really clever signature.
|
|
|
|