C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

Share tech news, updates, or what's on your mind.

Sign up to Post

Can a derived class method call a parameterized base class constructor to update a base class private member variable?

class BaseClass
{
      public:
            BaseClass(double balance);
      private:
            double balance;
};

class DerivedClass: public BaseClass
{
      public:
            DerivedClass();
            void ChangeBalance(double oldBalance);
};

void ChangeBalance(double oldBalance)
{
       double newBalance = oldBalnce * 2;

       BaseClass::BaseClass(newBalance);
}

In VS 2013, I set a Watch on the BaseClass private member called balance, and the BaseClass(newBalance ) constructor changes balance when called by the ChangeBalance function, but when it returns to the ChangeBalance function, balance reverts to the old value.
0
Hi All,

I'm looking for a way to hide a button on a 3rd party Windows form using COM or some other method.  Is there any way to achieve this?

My code is in C# but if I need to use "unsafe" code I have no issues.

Thanks.
0
I am using Visual Studio 2013 and coding in C++.

When in debug mode, stepping through the code, usually I see my code, and then some other code, probably part of the C++ library or something.

Problem is that I only wish to step through the code I created, since stepping through the other code is a waste of my time at this stage.

Is there a way to have VS step over the entire other code so I can focus on my code?

In simple terms, in VS, how do I step through my code only?
0
Hi, I developed a simple COM+ component using VS2010, installed it in "Component services" under my machine.

Image attached shows the installation. component installed
I also exported the MSi and the CAB file for this component.

Now I would like to consume my "AddNums" method of ICalc in a simple C++ client, locally, i.e on the same machine but using the MSI and CAB file as if I am using it from a remote machine. Just don't want to go through the trouble of setting up another machine in my home network right now.

Please give me step by step instructions to accomplish this. thanks.
0
I am new to C++, and I don't want to hard code a .txt file path, so is there a function that returns the path to the current .cpp file, which is found in the regular Source folder?

Thanks
0
Hello experts

Please help how to write and read a simple structure , structure contains one date field and one integer.

I need this structure data to access from other process.

Thanks in advance
0
Yes. It's homework.  The instructions are:  You must overload the bracket operators to allow the user efficient, array-like access to the contents of the deque. Like the standard deque, your interface must give the user the illusion that they are working with a single dimensional array.
My function here is not correct but it gives the illusion of an array. I need some help with the operator overloading part.  Thanks.
void test_at_operator() {
   Deque q;
   cout << "Create deque" << endl;
   for (int j=0; j<10; j++) {
      cout << "Insert " << j << " into back of deque." << endl;
      q.push_back(j);
   }   
   for (int j=0; j<10; j++) {
      cout << "at(" << j << ") = " << q.at(j) << endl;
      cout << "q[" << j << "] = " << q[j] << endl;
   }   
}

Open in new window

Output:
at(0) = 0
q[0] = 0
at(1) = 1
q[1] = 1
at(2) = 2
q[2] = 2
at(3) = 3
q[3] = 3
at(4) = 4
q[4] = 4
at(5) = 5
q[5] = 5
at(6) = 6
q[6] = 6
at(7) = 7
q[7] = 7
at(8) = 8
q[8] = 8
at(9) = 9
q[9] = 9
0
hello, I need help with a bubble sort for my V_prime_matrix. I watched a youtube video of how it is done, but I am getting errors. This may be due to becasue I have the sorting function outside of int main.

Can anyone help me?


#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <fstream>
using namespace std;

ofstream output_file; //declare file to output results to

void display_opening_logo(); //function declaration for the opening logo
void costMatrix();			 //function declaration for cost matrix
void construct_V_prime_matrix();
void sorted_V_prime_matrix();
void construct_d_prime_matrix();
float f_star();
void calculateVmatrix();    //function declaration for the to-be calculated V matrix
const char SKIP = ' ';

int C_matrix[4][4] = { 0 };
int V_matrix[4][4] = { 0 };
int f_bar[1][1] = { 0 };
int V_prime_matrix[6][1] = { 0 };
int d_prime_matrix[1][6] = { 0 };

int d_matrix[4][4] = { { 0, 8, 10, 2 },
					   { 8, 0, 4, 7 },
					   { 10, 4, 0, 9 },
				       { 2, 7, 9, 0 } };

int p_matrix[4][4] = { { 0, 4, 2, 3 },
					   { 4, 0, 8, 27 },
					   { 2, 8, 0, 30 },
					   { 3, 27, 30, 0 } };

double b_matrix[4][4] = { { 0, 0.5, 4, 1 },
						  { 0.5, 0, 0.5, 0.33333333333333333 },
					      { 4, 0.5, 0, 0.1666666667 },
						  { 1, 0.3333333333333333, 0.1666666667, 0 } };



int main()
{
	int i, j, x, k;

	display_opening_logo();											//function call for the opening logo
	cout << setw(16) << SKIP << endl;
	cout << "Press

Open in new window

0
I'm new to Qt but having trouble finding answers or a solution  to something which I had assumed would be quite simple. My question on qt-project.org hasn't even had any responses.

I've extended QWebView with the hopes of overriding paintEvent.

I want to grab the rendered web view, "post process it" (ie. filter, invert colors, that sort of thing) and then display the processed result on the widget.

Here is what I have so far and below I will describe where it goes wrong:

void QMyCustomWebView::paintEvent(QPaintEvent *event)
{
    QWebView::paintEvent(event);

   if (!bGrabbing)
    {
        bGrabbing=true; // member variable to prevent the recursion when grabWidget also calls paintEvent.

        QPixmap pixmap(QPixmap::grabWidget(this));
        bGrabbing=false;

        QImage imgProcessed = pixmap.toImage();
        imgProcessed.invertPixels();

        QPainter paintFinal(this);
        paintFinal.begin(this);
        paintFinal.drawImage(0,0, imgProcessed);
        paintFinal.setPen( Qt::blue );
        paintFinal.drawEllipse(10,10,40,40);

        paintFinal.end();

        imgProcessed.save("c:\\test.bmp");
    }
}

Open in new window


Note I'm saving an image test.bmp.. As this runs, test.bmp actually contains what I would expect to see on screen.. The rendered WebView, with inverted pixels, and a small blue circle drawn over it.. so "imgProcessed" holds exactly what I'd expect.

But when I run it, what I see on screen is as if I hadn't even sub-classed QWebView

So I feel like that flag bGrabbing is a hack but since I'm new at Qt I don't know.  I'm finding that all of the ways of "grabbing" a widget (ie. render, grabWidget) all end up recursively calling paintEvent again and as stated, my "processed image" when saved to disc shows exactly what I want to show on screen.. So why is my QWebView widget not updated with the proper image? What am I doing wrong?

Thanks!
0
Hi..
Any idea how I can convert this to C#

struct extrema {
    int *mins, *maxes;
    extrema();
    ~extrema();
    void alloc(int size);
    void dealloc();
    void update(point prev, point cur);
} horizExtrema, vertExtrema;


I think it's something like  ?????

public class extrema
{

      public int mins;

      public int maxes;

      void update(point prev, point cur);
}
0
Hi,

I have a MFC dialog that has few controls on it (like web browser, buttons etc).
I want this MFC dialog to be reused by other dialogs in my project.

Like, if I can convert this into an active-x control or a custom control, I can just use the whole dialog and embed it onto another parent dialog.

Is there a way I can do this?

Thanks,
0
Hello, I'm using Slick Edit version 6.01.7601  Service Pack 1.

I'm at opening brace.  How do I go to to closing brace?   Or how do I highlight opening and closing brace so I can see the block ?
0
Hi Experts,
I know this is almost 100% not possible, but just in case.  Is it possible to listen on a port on a machine (on localhost), where if the server is running in a given session, it won't be visible to other sessions?

Or, is there a way to communicate from a web browser other than using plugins and other than using http requests to something on localhost?

Just brainstorming.

Thanks,
Mike
0
hello, does anyone know how to send output to a file and screen simultaneously?
Currently my code only sends the output to a txt file and not the screen.

Can anyone help me?

Im not sure if i need to post my code for this, but let me know if you need me to
0
Hi all,

Here's my code:

SQL = SELECT ID,X,Y,A,TYPEID, vid  FROM (SELECT ID,A,X,Y,TYPEID,  (SELECT TOP 1 ID FROM DETAILS d WHERE pos.ID = d.ID) AS vid, row_number() over (partition by ID order by CREATEDTIME desc) as rn FROM POST pos) AS ss WHERE rn = 1;

CDatabase* pDatabase = new CDatabase();
pDatabase->Open(_T(""),FALSE,FALSE,LPCTSTR(sDsn));
CRecordset rs( pDatabase );
rs.m_bUseODBCCursorLib = TRUE;
BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,CRecordset::readOnly);
while(!rs.IsEOF() )
{
    CDBVariant v;
    memset(&v,0,sizeof(CDBVariant));
            
  rs.GetFieldValue((short)0, v, SQL_C_SLONG);
   //always the ERROR here
}

I searched high and low, but so far unable to solve this.

Maybe there's something wrong with my SQL? But
this only happens on SQLServer (I tried different databases on different versions).
Works fine in DB2.

Please help.
0
Hi

 I am trying to write a certain number of bytes, pointed by a pointer, p, to a file called myfile.

int numbytes=sizeof(float)*56;

FILE *myfile;
myfile=fopen("out.txt","w");  //returns a <Bad Ptr>
memcpy(myfile,memoryPtr,numbytes);

I noticed that myfile has a value 0x57251448 but it also says <Bad Ptr>. However, i read some confusing remarks on the web saying that might not necessarily mean something bad i,e <Bad Ptr> might just mean NULL pointer.

However, when i proceed with that in mind and I do memcpy, Visual Studio crashes and I am sent to some dbgheap.c file where I get an error at

/* check if the heap was not allocated by _aligned routines */
        if ( nBlockUse == _NORMAL_BLOCK)
        {
            if ( CheckBytes((unsigned char*)((uintptr_t)pUserData & ~(sizeof(uintptr_t) -1)) -nAlignGapSize,_bAlignLandFill, nAlignGapSize))
            {
                // We don't know (yet) where (file, linenum) pUserData was allocated
                _RPT1(_CRT_ERROR, "The Block at 0x%p was allocated by aligned routines, use _aligned_free()", pUserData);
                errno = EINVAL;
                return;
            }


What's the best way to write a chunk of memory , pointed to by a pointer,  to a file? And what is wrong with the current way I am doing things?
0
Hi i need help multiplying 2 matrix arrays b_matrix and p_matrix such that it creates a V_matrix and then use that V_matrix to create the C_matrix.

This isnt necessarily 'matrix' multiplication, more so scalar, by that I mean i coded the formula such that the first row of the V_matrix will be 0 60 50 45.

Can anyone help me?
new-qap-ee-code-help.txt
0
Hello I would like help in multiplying 2 matrices in the attached code,  the 2 matrices being multiplied are the V_prime_matrix[6][1] and the d_prime_matrix[1][6] and the result matrix being f_bar would be a single number.

Can anyone help me?
QAP-EE-Code.txt
0
How do I convert the following to C#

struct fpoint : pair<double> {
    fpoint() : pair<double>() { }
    fpoint(double x, double y) : pair<double>(x, y) { }
};
0
Hi

I want to write out what i see in the memory pane in visual studio to a file. I know there exists a Binary Editor , but is it relevant? How can I accomplish the writeout?

So for example, let's say I put a pointer a and I see the following:
1
3
4
5
:

I would like to write out everything (1-5....) upto a certain memory address to a file.

thanks
0
Hi,

Writing unit tests, I was surprised by the behaviour described below, and I cannot see where the bug is. I am just calling the _utime() function to set the modification time for the file. When trying to get the modification time back via _stat(), the returned modification time is not the same.

#include <sys/types.h> 
#include <sys/stat.h>
#include <sys/utime.h>

#include <cassert>
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    string fname = { "test.data" };

    ofstream f(fname);
    f << "test content";
    f.close();

    // Check the existence of the created file.
    struct _stat stat;
    if (_stat(fname.c_str(), &stat)) {
        cout << "_stat() error";
        return 1;
    }
    assert((stat.st_mode & _S_IFREG) != 0);

    // The time to be used for testing.
    time_t christmas2003_t = 1072263600;   // 2003-12-23 11:00

    // Set the times of the file.
    struct _utimbuf ut;
    ut.actime = christmas2003_t;
    ut.modtime = christmas2003_t;

    if (_utime(fname.c_str(), &ut) == -1) {
        cout << "_utime() error";
        return 1;
    }

    // Get the modification time of the file (back).
    struct _stat stat_struct;
    if (_stat(fname.c_str(), &stat_struct))
    {
        cout << "_stat() error";
        return 1;
    }
    time_t mtime = stat_struct.st_mtime;

    // Compare the two times.
    if (mtime == christmas2003_t)
        cout << "OK\n";
    else
        cout << "failed (" << 

Open in new window

0
Hi.  I have an ATL/MFC COM simple object written in Visual C++ 6.0.  This COM object has a single method, Test(), that simply calls the MFC MessageBox() method to display a "hello world" message.

I am trying to use this COM object on 64-bit Windows 7.  I put the file for this COM object, TestLibrary.dll, into the SysWOW64 folder and ran as an administrator the command "regsvr32 C:\Windows\SysWOW64\TestLibrary.dll", which resulted in the following message: "DllRegisterServer in C:\Windows\SysWOW64\TestLibrary.dll succeeded."   When I try to create the COM object, for example in Microsoft Excel, however, I get the following error message: "Run-time error '429': ActiveX component can't create object."  Do you have any ideas as to why I cannot create the COM object on 64-bit Windows?  It works flawlessly on 32-bit Windows.

Thank you.
1
Following is a simple class A1 and it is being used in Main.cpp file.

CLASS: A1
#include <iostream>
#include <string.h>

using namespace std;

class A1 {
public:
	char* p;
	A1(const char* str){
		p = new char(strlen(str)+1);
		strcpy(p,str);
	}

	virtual ~A1(){
		delete p;
	}
};

Open in new window

---------------------------------------------
Main.cpp

#include "A1.h"
int main(){
 A1 s("go Gama");
 s.~A1();
 printf(s.p);
 printf("one\n");
 A1 u("go Beta\n");
  //u=s;
 printf(s.p);
 printf("two\n");
}

Open in new window

---------------------------------------------
Expected output: one , two
BUT i get :one , go Beta , two

How can s.p still have a value which I have added to another instance u?
0
#include "stdafx.h"
typedef unsigned short u16;
typedef unsigned long  u32;

int _tmain(int argc, _TCHAR* argv[])
{
  u16 x = 0;
  u32 y = 6;
  int z = 0;

  if ( (x - (y*7)) < 0)
  {
    z = 1;
  }

  return 0;
}

Open in new window

The problem is line 11, the if statement. Viewing the disassembly, the assembly code generated ends with a jmp statement, always skipping over the z = 1;, implying the condition is always FALSE no matter what values are used for x and y.

Why? Has something to do with mixing 16-bit and 32-bit integers.
disassembly.png
0
Mary has two job offers.  One pays $500 per week with a 15% commission.  The other pays $900 per week with 10% commission.  What must Mary's salary be in order to make the same salary at either job ?

What does 15% and 10% commission mean?  Is it 15% and 10% of total sales, which is unknown?

please explain this question ?
0

C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.