c++

Is there a way to flag (at compile time) "overriden" methods whose signatures don't match base signature?

Basically, I want the C# compiler functionality of its override keyword in my C++ code. class Base { virtual int foo(int) const; }; class Derived : public Base { virtual int foo(int); // wanted to override Base, but forgot to declare it const }; As we all know, the above code will compile fine, but yield some strange runtime be...

Linking with --whole-archive flag.

Hi, This problem is related to This question I asked yesterday. Now it seems that the linker flag --whole-archive forces the test object to be included in the binary. However, in linking with, g++ main.cpp -o app -Wl,--whole-archive -L/home/dumindara/intest/test.a -Wl,-no--whole-archive I get the following error: /usr/lib64/gcc/x8...

How to port Java interface codes into C++ abstract base class?

Im new in OOP programming and C++ and Im currently into learning design patterns. Just grab the Head First Design Patterns book to learn from. Its actually great and Im already getting hold into the basic concepts.The first chapter talks about programming to an interface rather an implementation. Unfortunately for me though, the exampl...

Trouble understanding whence a copy constructor came

Hello everyone :) I have the following small code: template <typename T> class V { public: T x; explicit V(T & _x) :x(_x){} }; int main() { V<float> b(1.0f); // fails return 0; } And it happens to fail. The message returned by g++ 4.4.5 is: g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d...

Reading from a file in C++ and sending to socket until eof

I am trying to read from a file and write the output to a socket in C++. However when trying to compile my code I get two errors. One is #include <cassert> #include <arpa/inet.h> #include <cstdlib> #include <iostream> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <...

Using *this in C++ class method to fully overwrite self instantiation

Is the following code safe? (I already know it compiles properly.) void Tile::clear() { *this = Tile(); } int main() { Tile mytile; mytile.clear(); } ...

Is inheritence of concrete classes evil?

I use interfaces/abstract base classes for most of my types and don't often inherit from concrete classes but I've recently run into a situation where either inheritance or composition is desired. I've been aware of the adage "program to an interface, not an implementation" but recently decided to dig deeper. I've seen arguments again...

C++: Modifying array values for const

Hi, Consider the following: int a[2]; cin >> a[0] >> a[1]; const int D = a[1] - a[0]; cout << D << "\n"; a[1] = 5; a[0] = 2; cout << D << "\n"; I'm a bit confused now. Why does it print the same value for D? Why doesn't changing the array values change the value of D? At what point in time is the value of D determined and stored?...

Function Templates - Explicit specialisation vs Global Functions (C++)

I know that Function Templates are used so as to make the functions portable and so that they could be used with any data types. Also Explicit Specialization of templates is done if we have a more efficient implementation for a specific data type. But then instead of Explicit Specialization we could also just code a Nontemplate Functio...

Memory allocation for member functions in C++

#include<iostream> using namespace std; class A { }; class B { public: void disp() { cout<<" This is not virtual function."; } }; class C { public: virtual void disp() { cout<<"This is virtual f...

Implicit conversion not happening

Hello again :) The last question I asked was something I stumbled upon when trying to understanding another thing... that I also can't understand (not my day). This is quite a long question statement, but at least I hope this question might prove useful to many people and not only me. The code I have is the following: template <typen...

operator overload

I am working on this project just trying to keep up my c++ knowledge. Anyways, I am getting many, many errors when i try to implement an operator overload. Not sure why. #include "students.h" #include <iostream> #include "Quack.h" using namespace std; void main() { quack* classmates = new quack; classmates->pushFront(students("core...

Is it possible to have an animated QSystemTrayIcon?

I can't seem to find any info about this. but a lot of kde apps use animated icons. As i know it setting as QIcon a gif won't work, as only first frame will be displayed. ...

How do I know when one is done entering cin with \n? (loop)

From Australian voting problem: A bot will keep putting information and it can reach 1000 lines. Example of what he'll enter: "1 2 3 2 1 3 2 3 1 1 2 3 3 1 2 " How do I know when he has finished entering information? There is an extra \n at the end and that's my only guess on where to go. cin doesn't seem to detect \n, but getchar() a...

How to build FLTK to using with Netbeans (Windows)

How to build FLTK to using with Netbeans (Windows), i have tried but not success. Help me ...

Linker driving me mad! Please help.

Hi, I have 3 tiny files which I use to make a static library and an app: test.h #ifndef TEST_H #define TEST_H class Test { public: Test(); }; extern Test* gpTest; #endif test.cpp #include "test.h" Test::Test() { gpTest = this; } Test test; main.cpp #include "test.h" #include <iostream> using namespace...

c++ const member function that returns a const pointer.. But what type of const is the returned pointer?

I apologize if this has been asked, but how do I create a member function in c++ that returns a pointer in the following scenerios: 1. The returned pointer is constant, but the junk inside can be modified. 2. The junk inside is constant but the returned pointer can be modified. 3. Neither the junk, nor the pointer can be modified. Is i...

Pros and cons of 'inline'

First of all, I would like to state the facts I know about 'inline', so that you don't bother to restate them. An inline function is a special kind of function whose definition must be available in every translation unit in which the function is used. It is a hint to the compiler (which it is free to ignore) to omit the function call,...

STL related seg fault in C++ std::string ??

Does anyone point when can the below seg fault occur, as below: - heap Corruption - Memory leak - Flaw in the STL implementation of Strings 0xf0f1d672 in std::__default_alloc_template<true, 0>::allocate(unsigned int) () from /usr/lib/libstdc++.so.5 To give some context, the stack trace is as below: #0 0xf0f1d672 in std::__default...

QT separator widget ?

Greetings all, Is there any widget to separate two QWidgets and also give full focus to a one widget. As shown in following figure ? Thanks in advance, umanga ...