overloading

Singleton with two getInstance() methods handing over a parent pointer?

坚强是说给别人听的谎言 提交于 2019-12-11 11:07:01
问题 I am still working on my Logger and I like the idea of a Singleton but my Logger derives frm QDialog, thus I would like to handle my Parent QWidget* MainWindow pointer when I call it first: class Logger : public QDialog { Q_OBJECT private: explicit Logger(QWidget* parent = 0); public: static Logger& firstInstance(QWidget* parent = 0) { static Logger theInstance(parent); return theInstance; } static Logger& instance() { return theInstance; } //.. } So I would call Logger::firstInstance(this);

c++ overload operator new delete,

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:00:02
问题 Hi this is a little complicated so please let me know if any of this does not make sense, our team is writing a C++ application and we have previously had operator new overloaded. Recently I ran into this article: http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml about how to get debug information with our memory allocations. All the files within the application #include one file where we have compile-time platform configurations, and within that file I added the following:

A confusion about c++ function overloading

与世无争的帅哥 提交于 2019-12-11 09:53:06
问题 I was trying out default argument values and function overloading in c++ by compiling the following code and I was surprised by the output which was : Line 19: error: call of overloaded 'add()' is ambiguous The code I compiled is : #include <iostream> using namespace std; void add(int a=1, int b=1){ cout<<a+b; } void add(){ int a =2, b=2; cout<<a+b; } int main(){ add(); return 0; } Any explanations why it is ambiguous? Thx in advance. 回答1: Because both signatures match the call. add(); can be

iota increment vector of a class c++

落花浮王杯 提交于 2019-12-11 09:44:27
问题 I recently have been taking advantage of the <numeric> iota statement for incrementing a vector of type int . But now I am trying to use the statement for incrementing an explicit class with 2 members. So here is the usage with a vector of integers: vector<int> n(6); iota(n.begin(), n.end(), 1); Given that Obj class has an integer member called m . The constructor initializes m to its corresponding integer argument. Here is what I am trying to do now: vector<Obj> o(6); iota(o.begin(), o.end()

Overload JNI Method

被刻印的时光 ゝ 提交于 2019-12-11 09:37:41
问题 I have an existing JNI method with two parameters. Been around for a while, in use, so I don't want to just change it lest the wrath of angry customers be unleashed. But, I now need to make an adjustment. So, I thought, make a second overloaded method with the extra parameter and deprecate the two-parameter version. That part went fine, jar builds and runs with no issues. The problem is in the C++ side... I defined two methods, one being a wrapper for the other (two parameter calls the three

Operator Overloading: Ostream/Istream

萝らか妹 提交于 2019-12-11 07:23:59
问题 I'm having a bit of trouble with a lab assignment for my C++ class. Basically, I'm trying to get the "cout << w3 << endl;" to work, so that when I run the program the console says "16". I've figured out that I need to use an ostream overload operation but I have no idea where to put it or how to use it, because my professor never spoke about it. Unfortunately, I HAVE to use the format "cout << w3" and not "cout << w3.num". The latter would be so much quicker and easier, I know, but that's not

Do I need to define `operator==` to use my class with standard containers?

亡梦爱人 提交于 2019-12-11 07:08:19
问题 I'd like clarification on the C++ standard, specifically where it says (my interpretation) in section 20.1.3 that "for class T and an instance of class T called x, T(x) must be equivalent to x" for the class to work with standard containers. I couldn't find a definition of 'equivalent'. Does this mean that I have to define operator== as a member of my class, so that T(x) == x returns true? 回答1: Equivalent is purposefully vague. (To avoid things like implying operator== must be defined; it

c++ overloading a function default argument

£可爱£侵袭症+ 提交于 2019-12-11 06:49:13
问题 I have a widely used c++ library which holds a method such as: foo(); I want to overload this function to have a default argument such as: foo(bool verbose=false); does this change force me to recompile every code that uses this function? can't a call to foo() without the argument keep working as the no-args-signature didn't change? by the way - I'm using gcc thanks 回答1: does this change force me to recompile every code that uses this function? Yes, and the compile will fail, since there will

C++ overloaded output operator

老子叫甜甜 提交于 2019-12-11 06:39:30
问题 so I am coding my c++ homework assignment and there is a final part where he wants us to Replace the formatted output method (toString) with an overloaded output/insertion operator. TO be 100% honest I have no idea what he means by this. I've searched around a bit and found example codes using an overloaded insertion operator, but can't seem to find how to incorporate it into my code. Though I think I may be looking in the wrong place. My toString is as follows: string Movie::toString() const

multiple parameters passing with method overloading in WEB API

ⅰ亾dé卋堺 提交于 2019-12-11 06:39:15
问题 I have following methods in Repository Class public class LibraryRepository : IBookRepository { LibraryContext context = new LibraryContext(); public decimal findBookPrice(int book_id) { var bookprice = ( from r in context.Books where r.Book_Id == book_id select r.Price ).FirstOrDefault(); return bookprice; } public decimal findBookPrice(int book_id, string bookname) { var bookprice = ( from book in context.Books where book.Book_Id == book_id & book.Book_Title == bookname select book.Price )