565 Posted Topics

Member Avatar for esesili

A multitude of errors, mostly caused by trying to write everything in on go. (a) Patient includes an instance to Doctor. Therefore you must have a declaration of Doctor before Patient is declared. If it was just a reference or pointer you could have used a forward declaration e.g [icode] …

Member Avatar for StuXYZ
0
129
Member Avatar for nielsp

You problem is scope. Let me walk through it even if you are familiar with it. (a) If you want to use m in class X. All is ok. (b) If you want to use m in class Y. Again all is ok, assuming Y does not define a local …

Member Avatar for nielsp
0
4K
Member Avatar for PC_Nerd

Using gcc, [icode]#include <string.h>[/icode], provides a back-compatability system for stuff like [icode]using std::memcpy;[/icode] etc... You include that when you are using code that does not use the std::strcpy form but you want to just write [ICODE]strcpy(...)[/ICODE]. Since you almost never want [ICODE]using namespace std; [/ICODE]it is a nice half-way house, …

Member Avatar for StuXYZ
0
6K
Member Avatar for nanchuangyeyu

I think that you are after the distance algorithm e.g. [code=c++] std::vector<int> A; // ... stuff here vector<int>::iterator i = find(A.begin(), A.end(), 9); // can use std::vector<int>::difference_type // or static_cast to int etc. long int index=std::distance(v.begin(),i); [/code] Note it work with std::list and other containers with a reversible iterator. The …

Member Avatar for StuXYZ
0
268
Member Avatar for daviddoria

I normally think it is better to wrap these kind of fabs() type test in a testing namespace , that provides a template form like this [code=c++] namespace Approximate { template<typename T> bool equal(const T& A, const T& B,const double precision = 1e-4); template<typename T> bool notEqual(const T& A,const T& …

Member Avatar for StuXYZ
0
186
Member Avatar for xcktinios

Depending on the problem use a template parameter. But the trick is to use a common base class. Imagen this: [code=c++] class pixelBase { // ... Stuff ... virtual void setPixel(); }; template<int pixelType> class pixelItem : public pixelBase { virtual void setPixel(...); }; [/code] This doesn't always give you …

Member Avatar for StuXYZ
0
91
Member Avatar for athlon32

If you are writing a Pong game, I think that you are going to learn a lot, so well done. Second AI in Pong is interesting, there are at least three models: (a) pure deterministic. That is the computer calculates exactly where is wants to be and tries to go …

Member Avatar for athlon32
0
137
Member Avatar for DomoCobra

Your zero's + poles are correct, your LCCD is incorrect as you have missed a term.

Member Avatar for StuXYZ
0
80
Member Avatar for RiceFiend

This code is NOT fine. The problem is the there is not a copy constructor or an assignment operator. The requirement for using vectors SAFELY is that they work. If you do not provide them, then the compiler uses a default version. Your class requires that you has std::string which …

Member Avatar for StuXYZ
0
135
Member Avatar for S.A.H

Well types like int, float etc are fundermental, i.e. they are not classes. How the are converted into machine code requires examination of the compiler source code. Types like ostream and string are part of the standard lib. So they are classes. This means that you can look at the …

Member Avatar for Salem
0
116
Member Avatar for Peter_APIIT

Well the basic FFTs are available in the GSL (gnu-scientific lib.) [URL="http://www.gnu.org/software/gsl/manual/html_node/Fast-Fourier-Transforms.html"]http://www.gnu.org/software/gsl/manual/html_node/Fast-Fourier-Transforms.html[/URL] If you are doing polynominals, you are very likely to need the complex form, and depending on exactly how you set it up the 2D form of that. However, you should also look at FFTW3 [URL="http://www.fftw.org/"]http://www.fftw.org/[/URL] which is …

Member Avatar for StuXYZ
0
141
Member Avatar for gretty

Several things from your question: First the string part. You have many options (a) you can indeed use insert but the method requires an iterator to define the position for insertion. (b) the easiest to use simply += e.g [code=c++] char p='x'; std::string A("test"); A+=x; // A is now testx …

Member Avatar for jephthah
0
703
Member Avatar for fadia

First off, I agree that you should compile often. Second: The main point, there are FAR too many fixed numbers. e.g. [icode]"Round trip from Tokyo to Florida,America 2500$ per"[/icode] That is horrific. Put [code] const double TokyoFloridaCost(2500); const double YenDollarExchangeRate(14.3); [/code] at the top of the code and use the …

Member Avatar for ithelp
0
129
Member Avatar for andonyan

Quadratic multilication: If you multiply two quadratics together you don't normally get another quadratic, (normally it is a quartic ([tex]x^4[/tex]) ). What that really means is that quadratic(ness) should a property of a class, not itself a class. [Assuming that you are going to require multiplication] So write a polynominal …

Member Avatar for Sky Diploma
0
324
Member Avatar for Usura

You can do this in a number of different ways. What you seem to have here is two processes to do, which have different efficient in different containers. That means that you have to have a compremise. So, let use construct a simple consideration with the basic items: You can …

Member Avatar for StuXYZ
0
110
Member Avatar for imaloner

At a guess. I think that your problem is that you are using long, by itself, and not long int or long unsigned int , or long double etc. Yes there is a fall back of long to long int, but does that still apply to long* and going to …

Member Avatar for imaloner
0
820
Member Avatar for Chumpcash

while you are fixing this. Please note that you often write [code=c++] for (int count=0;count<customer;count++); { // Stuff } [/code] Observe the semi colon after the for loop that should not be there since the body is not going to get executed until after the pointless loop. gcc gives warnings …

Member Avatar for Yiuca
0
175
Member Avatar for Ray Gray

This is C++ not C, so I would have written: [code=c++] b= -1*static_cast<int>(x)/2; [/code] The main advantage of this is the you have an explicit bracket around the section you are casting and it is a BIG flag that you are changing type. Something that in numerical code is often …

Member Avatar for ArkM
1
104
Member Avatar for Peyton

Well the problem seems to be that you expect the array to be terminated with a 0 . This is a mess. What I think you have done is confuse the normal mechanism for strings e.g. [code=c++] char* X="Fred"; // This gives // X[0]=='F' ... X[3]=='d' X[4]==0 [/code] with any …

Member Avatar for Peyton
0
105
Member Avatar for nanchuangyeyu

With that kind of error message I would be expecting that you have over or under run the array indexes. If you post some more code, we can have a look. But check that you don't let your indexes get to 400 or something. (or negative!).

Member Avatar for ArkM
0
212
Member Avatar for SallyJ

This thread is getting a bit messy. So I am going to write a quick summary and how I would tackle the problem. First: Coordinates are almost never integers, and once you have solved a 2d problem you often need a 3d solution, and sometimes higher dimensions. What has been …

Member Avatar for ArkM
0
2K
Member Avatar for musique

> What is wrong with my sorting function? I am trying to put numbers in ascending numbers. Nothing, in the fact that it actually works, BUT it is a bubble sort and hence very inefficient. If you are still having problems check your calling routine, are you using an array …

Member Avatar for musique
0
255
Member Avatar for abhi_elementx

Ok it is a singleton, so there are several methods, but teh stuff above doesn't look 100% ok. First : if you are going to use a singleton you want to be 100% certain that there are no repeats. That means that if you want to use the static pointer …

Member Avatar for MrSpigot
0
103
Member Avatar for Clockowl

First of all, Narue's explaination is really well done (as usual). Second, has ClockOwl noticed that REGARDLESS of the template issue he has written the algorithm wrong and you get absolutely no items in x after kill_dupes is called you might as well write [code=c++] template<typename T> void kill_dupes(vector<T>& X) …

Member Avatar for siddhant3s
0
2K
Member Avatar for soulbee1

Sorry, but most of these solutions are inelegant and that is because to achieve randomness they require an excessive number of random number calls: (a) Shuffling the stack by selecting two cards and exchanging requires about 7 times the deck of length to get to nearly random on a 52 …

Member Avatar for nucleon
0
732
Member Avatar for Kungu

First : As pointed out there are vectors of vectors. That is ok. But often you want a 2d array, i.e each column is the same length. So try the boost::multi_array. Lots better. Second : you can do what you want with pointers/new/delete etc BUT you have to get it …

Member Avatar for StuXYZ
0
144
Member Avatar for jesseb07

Looks to me that you are not creating an instant of the template class for `<int>`. You have put the link body in a .cpp file. That is perfectly acceptable and good practice if the body is large. BUT you have not created an explicit instance of it. So add …

Member Avatar for jesseb07
0
6K
Member Avatar for mhalls

You have several potentual problems : (a) If you have an extra character at the end of the file (e.g. '\n') Since you test fin.eof ONLY at the start of each sequence you probably read the array then find that you are not at the end of the file , …

Member Avatar for StuXYZ
0
108
Member Avatar for bobsta

Ok: Not perfect but a good attempt: First off scoping rules: if you have a class variable e.g. [code=c++] class A { int index; }; [/code] Then that variable is effectively hidden by this [code=c++] class A { int Index; void run(int Index) const { Index+=20; } }; [/code] Note …

Member Avatar for bobsta
0
382
Member Avatar for daviddoria

However, you can use the std::distance function to determine the distance between two sequentual iterators. e.g. [code=c++] std::vector<int> A; std::list<int> B; // ... populate A,B: std::vector<int>::iterator AIter=find(A.begin(),A.end(),7); std::list<int>::iterator BIter=find(B.begin(),B.end(),7); std::cout<<"Distance Vector == "<<distance(A.begin(),AIter)<<std::endl; std::cout<<"Distance List== "<<distance(B.begin(),BIter)<<std::endl; // THIS DOES NOT WORK:: // std::cout<<BIter-B.begin() <<std::endl; [/code] The list iterator is not …

Member Avatar for StuXYZ
0
95
Member Avatar for phoenix2391

First off rayone is just random troll. Second: Your problem is that you have (a) forgotten to put a endl after the output and (b) forgotten that x and y are separate entities. So you need [code=c++] cout<<x<<y<<endl; [/code] finally you forgot that after an if you need { }, …

Member Avatar for StuXYZ
0
83
Member Avatar for daviddoria

The list you are after in in [URL="http://gcc.gnu.org/gcc-4.3/cxx0x_status.html"]http://gcc.gnu.org/gcc-4.3/cxx0x_status.html[/URL] I am assuming that you are using 4.3. However, I am sligthly mystified , I though that you can only write what you have if you are using static or const. If you have the C++0x reference could you/someone post it please. …

Member Avatar for daviddoria
0
85
Member Avatar for nito28

And your problem with this assignment is..... Suggested reading: [URL="http://www.daniweb.com/forums/announcement8-2.html"]http://www.daniweb.com/forums/announcement8-2.html[/URL]

Member Avatar for StuXYZ
0
134
Member Avatar for shea279

Sorry but anubis' process injection code, is normally used to put code into running windows processes for the purpose of running a rootkit. As far as I can tell. So why should we help given the site rules and likely purpose. The only good news is you don't seem to …

Member Avatar for shea279
0
259
Member Avatar for sid78669

Well depite the fact that this looks awful, you almost definately have a memory leak. You initialize line to fslen+10, whatever fslen is. Then you do not delete it. However, as vmanes says, you are not giving us much to go on. I would, at the minimum post the class …

Member Avatar for sid78669
0
193
Member Avatar for maru2

If you are using that much memory, you will be much better off using the boost array/multi_array classes. Then you will be better off using Blitz. Word of warning: write the code using boost/stl untill it works with smaller data sets. THEN use Blitz. Otherwize the error messages and other …

Member Avatar for StuXYZ
0
216
Member Avatar for snap!

It still amuses me to see stuff like: [quote](after any other discount is subtracted).[/quote] It doesn't matter what order you apply you % discounts. However, rather than that : this is c++ the advantage that gives you (along with many other languages) is you can code stuff as functions or …

Member Avatar for StuXYZ
0
92
Member Avatar for DemonGal711

Answer is: Start again You have [code=c++] while (getline(cin, info) && info != "") { if ( isInVec(word[info.length()], info) == false) word[info.length()].push_back(info); } [/code] Now word starts empty, so IMMEDIATELY, you access work[X] were X is a large number. Then you push back to that place. That is memory corruption. …

Member Avatar for DemonGal711
0
90
Member Avatar for robotnixon

You can't copy it to a set and back again without breaking the order. Sets store on a compiler defined manor but normally red-black trees. Hence you will destroy the order. The easiest way is to copy to another vector sort, unique and then find the copies. Another slightly more …

Member Avatar for robotnixon
0
553
Member Avatar for bluemm87

In addition, replace the semi colon on line 21 with a colon ( : ). Swap line 22 with line 23. That will avoid a compiler warning.

Member Avatar for StuXYZ
0
163
Member Avatar for Seapoe

First off: The polynominal class, it is a start but you have a number of things to adjust. First off polynominals have three common types of coefficient: complex , floating point (double etc) or polynomial. Note the last one: if you want to express [TEX]3y^2+xy+x^2+1 =0[/TEX] then you will want …

Member Avatar for monkey_king
0
109
Member Avatar for daviddoria

Nucleon is 100% correct that it gives "multiple definition of void Output<unsigned int>" on standard compliant compilers. The standard says that if you put implimentations in a declaration then ALL used specializations must be availiable at that instance. Some compilers do help you out here BUT it is not standard …

Member Avatar for nucleon
0
3K
Member Avatar for monkey_king

Ok you have made several little errors/annoyances and one misunderstanding as I see it. (a) First you [ICODE]#ifndef TEMPLATED_FOO_H[/ICODE] does not finish (b) You use a chained #include system. Please don't, it can be done but write .h file for the classes adn use #include's in the cxx. That will …

Member Avatar for StuXYZ
0
847
Member Avatar for MrPickle

Yes certainly you can do that but you have to resolve the instance at some point. So perhaps you want it is another templated class. [code=c++] template<class First, class Second> struct foo { First f; Second s; }; template<typename A,typename B> struct Other { std::vector< foo< A, B > > …

Member Avatar for StuXYZ
0
99
Member Avatar for peacerosetx

You don't seem to have posted enough code for anyone to tell but are you using: [icode]m_pEcoAreaTeam = new EcoAreaTeam();[/icode] and then the class does not have m_pEcoAreaTeam and you have a scope issue?? If the class has m_pEcoAreaTeam check the spelling. And why the use a global m_pEcoAreaTeam or …

Member Avatar for peacerosetx
0
108
Member Avatar for thingstealer

Ok there is no way for us to know the problem but you most likely have a macro [icode]#define size ....[/icode] somewhere in the mess of headers. Have you stripped this down to the minimum- does it still work. If you put a line [icode]#undef size[/icode] just above the [ICODE]PQueue::PQueue[/ICODE] …

Member Avatar for thingstealer
0
148
Member Avatar for Avaviel

Note: [Ark -- I know you know this] but I think it is worth pointing out. If you think that you HAVE to put the template stuff in a single .h file this is wrong. It is ok and works but really really quickly leads to serious slow down on …

Member Avatar for StuXYZ
0
84
Member Avatar for halfnode

First off, well done for using code tags for your first post. Second, your error is that you are returning 0 but actually need to return a string. Try as the last two lines of padBlanks, this: [code=c++] blank+=string1; return blank; [/code]

Member Avatar for ArkM
1
199
Member Avatar for viki0077

Syntax mainly: Constructors use variable initializers and an additional code block which happens after initialization. i.e. [code=c++] Customer() : id(0),name("X") { // code block here } [/code] the second version is wrong because you have an extra (). (write long int please!). The only other thing you are going to …

Member Avatar for viki0077
0
122
Member Avatar for Omega037

Before I tell you what I think is wrong I am going to tell you what I think has lead you to not being able to solve this. **First:** the layout. It is a mess. Code has to be tidy. I understand you are most likely not a CS grad …

Member Avatar for StuXYZ
0
192

The End.