|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Files:
pirma_lib.h - http://www.paste.lt/paste/de66c8b700...19eea1318d1993 pirma_lib.cpp - http://www.paste.lt/paste/050b916516...8f54a0193fe564 pirma.cpp - http://www.paste.lt/paste/6753553152...703393d79d6f67 I am using std:: in pirma_lib everywhere and this why I do not need to use "using" and and std library which later could make some problems and it still does now. The problem is that when everything was in one file it was working perfect and now I decided to put everything in separate files. This way I made direct calls (std: and removed "using namespace std;"from pirma_lib.cpp and this worked, I was able to compile this model (g ++ -Wall -ansi -pedantic -c pirma_lib.h); But I was not able to compile the main code. Every line where I was using "Aibe" class and it's methods was returning mistakes. But after commenting "using namespace std;" in pirma.cpp I did not get any error, but I should write to every cin, cout and etc std:: (make direct calls). The question would be how I should correctly move my class to separate file, make module? Why it throwing mistakes with that std (This one makes the most problems as I can see); - - - The second question. In pirma_lib.h there is a line: bool isSubSet(Aibe &other); But I would like to protect "other" Aibe instance and use "const Aibe &other", but inside it I am using length() method. (but I could easily get directly if I need). And this throws another mistake, that I can not use length() method in this case, but I then declare length: int length() cent; This should mean that length() can not change *this and I think that now it should allow me to call it, but again I am still getting mistake that it can not find such method at all. (It might be that I still does not understand how it works) Could someone explain why I can not call length() method? This mistake: pirma.cpp: In member function 'bool Aibe::isSubSet(const Aibe&)': pirma.cpp:101: error: no matching function for call to 'Aibe::length() const' pirma.cpp:20: note: candidates are: int Aibe::length() <near match> |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Feb 26, 2:26 pm, david <David.Abdurachma...@gmail.com> wrote:
> Files: > pirma_lib.h -http://www.paste.lt/paste/de66c8b70084d3174d19eea1318d1993 > pirma_lib.cpp -http://www.paste.lt/paste/050b9165168c61cc168f54a0193fe564 > pirma.cpp -http://www.paste.lt/paste/6753553152fe92e939703393d79d6f67 > > I am using std:: in pirma_lib everywhere and this why I do not need to > use "using" and and std library which later could make some problems > and it still does now. > > The problem is that when everything was in one file it was working > perfect and now I decided to put everything in separate files. This > way I made direct calls (std: and removed "using namespace std;"> from pirma_lib.cpp and this worked, I was able to compile this model (g > ++ -Wall -ansi -pedantic -c pirma_lib.h); > > But I was not able to compile the main code. Every line where I was > using "Aibe" class and it's methods was returning mistakes. But after > commenting "using namespace std;" in pirma.cpp I did not get any > error, but I should write to every cin, cout and etc std:: (make > direct calls). > > The question would be how I should correctly move my class to separate > file, make module? Why it throwing mistakes with that std (This one > makes the most problems as I can see); > > - - - > > The second question. > > In pirma_lib.h there is a line: bool isSubSet(Aibe &other); > But I would like to protect "other" Aibe instance and use "const Aibe > &other", but inside it I am using length() method. (but I could easily > get directly if I need). And this throws another mistake, that I can > not use length() method in this case, but I then declare length: int > length() cent; This should mean that length() can not change *this and > I think that now it should allow me to call it, but again I am still > getting mistake that it can not find such method at all. (It might be > that I still does not understand how it works) Could someone explain > why I can not call length() method? > > This mistake: > pirma.cpp: In member function 'bool Aibe::isSubSet(const Aibe&)': > pirma.cpp:101: error: no matching function for call to 'Aibe::length() > const' > pirma.cpp:20: note: candidates are: int Aibe::length() <near match> I am going to take a guess that you are passing a const reference to an object as a parameter to a function, which in turn is calling a method of that object which does not promise to not alter the data of the object. Aibe::length() needs to be Aibe::length() const; If the method does not alter Aibe's data If it does alter Aibe's data, than you can't pass a const object to Aibe::isSubSet, while Aibe::isSubSet calls Aibe::length. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
david wrote:
> Files: > pirma_lib.h - > http://www.paste.lt/paste/de66c8b700...19eea1318d1993 > pirma_lib.cpp - > http://www.paste.lt/paste/050b916516...8f54a0193fe564 pirma.cpp > - http://www.paste.lt/paste/6753553152...703393d79d6f67 With all due respect, be aware that many people concerned with computer security are NOT going to follow some unverified links. It's simply too dangerous. Next time copy and paste your code right into your message. And spend some time reducing it to the bare minimum necessary to illustrate your question[s]. > I am using std:: in pirma_lib everywhere and this why I do not need to > use "using" and and std library which later could make some problems > and it still does now. Not a clear statement. Separate into more than one sentence and review. > The problem is that when everything was in one file it was working > perfect and now I decided to put everything in separate files. This > way I made direct calls (std: and removed "using namespace std;"> from pirma_lib.cpp and this worked, I was able to compile this model > (g ++ -Wall -ansi -pedantic -c pirma_lib.h); Why are you compiling what appears to be a header file? > But I was not able to compile the main code. Every line where I was > using "Aibe" class and it's methods was returning mistakes. But after > commenting "using namespace std;" in pirma.cpp I did not get any > error, but I should write to every cin, cout and etc std:: (make > direct calls). This is not really a C++ language question, but perhaps your .h file has all the necessary includes and your .cpp doesn't. Try including your .h file into your .cpp and compile your .cpp instead. > The question would be how I should correctly move my class to separate > file, make module? Why it throwing mistakes with that std (This one > makes the most problems as I can see); This is not really a language question. > > - - - > > The second question. > > In pirma_lib.h there is a line: bool isSubSet(Aibe &other); > But I would like to protect "other" Aibe instance and use "const Aibe > &other", but inside it I am using length() method. (but I could easily > get directly if I need). And this throws another mistake, that I can > not use length() method in this case, but I then declare length: int > length() cent; This should mean that length() can not change *this and > I think that now it should allow me to call it, but again I am still > getting mistake that it can not find such method at all. (It might be > that I still does not understand how it works) Could someone explain > why I can not call length() method? > > This mistake: > pirma.cpp: In member function 'bool Aibe::isSubSet(const Aibe&)': > pirma.cpp:101: error: no matching function for call to 'Aibe::length() > const' > pirma.cpp:20: note: candidates are: int Aibe::length() <near match> Make 'length' function also const. Correct its implementation to avoid making changes to *this object. You need to both declare and _define_ the 'length' function as 'const'. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Those links dangerous? I doubt it, nope I am 100% it is safe and do
not worry about that. Sorry about that pirma_lib.h, that was typo it should be pirma_lib.cpp. The problem is that pirma_lib.cpp compiles fine with 0 errors and warnings, pirma_lib.h is included in pirma.cpp and I was not able to compile this codes, getting a lot of errors, huge amounts of it. I was thinking what could have caused it and I decided to comment line "using namespace std;" ir pirma.cpp and all errors there gone, but that would require always make direct calls to std library and I do not want that. The question is what could be causing this and why? What I did wrong moving my class to separate file? Because if I put everything in one file it works just perfect. And with those consts: int Aibe::length() const { // <- const return size; } bool isSubSet(const Aibe &other); // <- const void toArray(int **arr); std::string toString(); int length() const; // <- const error: Macbook:pirma marius$ g++ -Wall -ansi -pedantic -c pirma_lib.cpp pirma_lib.cpp:52: error: prototype for 'bool Aibe::isSubSet(Aibe&)' does not match any in class 'Aibe' pirma_lib.h:11: error: candidate is: bool Aibe::isSubSet(const Aibe&) Or I am still missing something? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
david wrote:
> [..] > error: > Macbook:pirma marius$ g++ -Wall -ansi -pedantic -c pirma_lib.cpp > pirma_lib.cpp:52: error: prototype for 'bool Aibe::isSubSet(Aibe&)' > does not match any in class 'Aibe' > pirma_lib.h:11: error: candidate is: bool Aibe::isSubSet(const Aibe&) > > Or I am still missing something? Yes, of course. Did you read the error message? Compare the two declarations in it. Then compare the definition of 'isSubSet' with its declaration. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
I see and I know what the problem is, but I still can not understand
how to fix it. How correctly I should write it. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Thanks, just decided to check the code this morning and yes, now I
noticed the problem. But the main and the biggest problem now is how to move my class to separate file, because this one still gives huge amounts of errors, almost on every line where I am using my "Aibe" class. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Sorry for so many posts I am making (We could say I am just keeping
you all up to date), the problem lies in my << overloaded operator. They I try to echo my class in this way: cout << "NNN : " << nnn << endl; // "<<" operator invokes toString() and worked fine then everything was in one place. Now it looks that compiler do not even check pirma_lib.h for this operator, but other operators seams to work. Any ideas why it ignores this one? |
|
![]() |
| Outils de la discussion | |
|
|