[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

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

Is it possible to create a cross-platform desktop application in Visual Studio 2017 that will run in both Windows 10 and Linux environments (how is it done)?  
I don't see any "New Project" options that stand out, nor much information on the web.

Thanks
1
Become a CompTIA Certified Healthcare IT Tech
LVL 12
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Hi I have a 2D vector in a library which gets populated with different types of data this part is working fine now I need to pass the 2D vector back to my main app from a function call but this function call is failing

Here is the structure that makes up the vector in the library and how I am trying to call the data in the vector from a function:
//Library code
typedef struct _DEVICEDETAILS
{
	std::string IPaddr;
	int HTTPPort;
	int HTTPSPort;
	int RTPSPort;
	std::string Model;
	std::string Name;
	std::string token;
	std::vector<std::string> RSTPURL;
	std::vector<char*> data;
	std::vector<size_t> datalen;
	std::string _mediaXaddr;
	int Encoding;
	int Width;
	int Height;
	int Quality;
	int FrameRateLimit;
	int EncodingInterval;
	int Bitrate;

}DEVICEDETAILS;

struct ONVIFDEVICE
{
	std::string MacAddr;
	std::vector<DEVICEDETAILS> _videotype;
};

ONVIFDEVICE m_MacAddr;
std::vector<std::vector<ONVIFDEVICE>> v_Device;

void GetOvifInfo(std::vector<std::vector<ONVIFDEVICE>> &returnInfo)
{
  other code .......
   int m_size =v_Device.size();
   v_Device.resize(m_size+1);
   v_Device[nFindDev].push_back(m_Mac); // info gets populated into each element here
   nFindDev++;
   
  //Need to do a deep copy from vector v_Device to  vector returnInfo

}

// Main App code
typedef struct _mDEVICEDETAILS
{
	std::string IPaddr;
	int HTTPPort;
	int HTTPSPort;
	int RTPSPort;
	std::string Model;
	std::string Name;
	std::string token;
	std::vector<std::string> RSTPURL;
	std::vector<char*>

Open in new window

0
I have following version of eclipse IDE installed in my computer:
Eclipse IDE for C/C++ Developers
Version: 2018-09 (4.9.0)

I created a workspace.  There are number of Templates for New C / C++ Project.
I need to import very large 'C' source code files into my project.  I won't be compiling code in eclipse.  I'll just be navigating source code.
Which Project template should I select?  Is there a way to create project without selecting a project template?
0
Yellow rect is the window it's moved from left to rightI am implementing a draggable window and in my mousemove i am setting it's position using MoveWindow() API but problem is while it is moving it is leaving its trace behind i have attached the image The place where it was present earlier is not getting erased, i have used OnEraseBackground to true and false
0
Hey!

I am developing an application using JetBrains CLion 2018.2.4 with cmake 3.12.2 and Visual Studio 2017 compiler.
Let me set up things first.

Here is the base class:
class Header
{
public:
   enum MessageType
   {
      Message = 100,
      Command = 101,
      InvalidMessage = 102
   };

   Header();
   Header(Header::MessageType messageType);
   virtual ~Header() = default;

   Header::MessageType GetMessageType() const;
private:
   Header::MessageType m_messageType;
};

Header::Header() :
   m_messageType(Header::MessageType::InvalidMessage)
{
}

Header::Header(Header::MessageType messageType) :
   m_messageType(messageType)
{
}

Header::MessageType Header::GetMessageType() const
{
   return m_messageType;
}

Open in new window


Here is the derived class:
class Message : public Header
{
public:
   Message();
   ~Message() = default;

   void SetMessage(std::string message);
   std::string GetMessage() const&;

private:
   std::string m_message;
};

Message::Message() :
   Header(Header::MessageType::Message),
   m_message("")
{
}

void Message::SetMessage(std::string message)
{
   m_message = message;
}

std::string Message::GetMessage() const&
{
   return m_message;
}

Open in new window


Here is how I'm acessing the function GetMessage();
int main()
{
   Reader reader;

   auto basePtr = reader.ReadAll(message);
   auto derivedPtr = std::dynamic_pointer_cast<communication::Message>(basePtr);
   std::cout << "read: " << derivedPtr->GetMessageType() << ";" << derivedPtr->GetMessage();
}

Open in new window


When I try to execute GetMessage() like up above, I get the error below:

Server.cpp.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall communication::Message::GetMessageA(void)const & " (?GetMessageA@Message@communication@@QGBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
Server.exe : fatal error LNK1120: 1 unresolved externals

Open in new window


It has to do with the function GetMessage() but I'm failing to see what is wrong. If I remove that call, everything compile fine.
Also, I do the exact same call in other class and it is working fine.
Help is needed!!!
0
dup2(int oldfd, int newfd);

Open in new window


This is an equivalent of:

close(int newfd);
dup(int oldfd);

Open in new window


By closing "newfd" first, it becomes the lowest-numbered unused file descriptor (normally). Because of that the oldfd is copied to newfd (dup system call). So far, everything is clear.

Now see: http://codewiki.wikidot.com/c:system-calls:dup2


dup2 is a system call similar to dup in that it duplicates one file descriptor, making them aliases, and then deleting the old file descriptor.

Actually I don't think the old file descriptor will be deleted?

See: http://man7.org/linux/man-pages/man2/dup.2.html

After a successful return, the old and new file descriptors may be used interchangeably.

If the old file descriptor will be deleted, then they would not say something like that. Is wikidot.com just wrong about this?
0
I'm trying to understand the structure of the open file table. During this search I'm reading things that look like (for me) they are in contrast with each other.

In a system there is a:

File descriptor table:
This table is located in user space and is associated with a certain process (per-process).

Open file table:
This table is located in kernel space and is associated with all processes (process-wide).

Entries in the file descriptor table point to the open file table. This all is clear. Now let's go to the structure of these tables. For example, see: https://elixir.bootlin.com/linux/v3.18/source/include/linux/fdtable.h#L24

struct fdtable {
        [...]
};

Open in new window


And:

/*
 * Open file table structure
 */
struct files_struct {
        [...]
};

Open in new window


Also this is clear. But now see for example: http://www.andrew.cmu.edu/user/gkesden/ucsd/classes/sp17/cse291-a/applications/ln/lecture5.html

Per Process File Information


struct files_struct { /* kept within task_struct (PCB) */
        [...]
};

Here they are talking about files_struct when it's about "per process file information". I don't understand this, because the open file table is process-wide. This is for example what they are saying:

The count variable tracks the number of files the process has open

But imagine ... two different processes point to the same entry in the open file table. I think …
0
Dear experts,

I am learning C++

I have some idea about Objects in C++

Is there an online course which can teach me 'objects' and ' Data Structures' in great detail?

Kindly suggest.
0
I am considering using a Rasberry Pi as an SBC (single board computer) with Android O/S installed and programming with Embarcadero RAD Studio 10.2  (C++ builder). Is there a library or other means of using the GPIO of the Rasberry Pi and other hardware features of the SBC ?
0
Question is related to C++ STL list::sort(Compare) where Compare is now a template.

I am looking for the correct syntax to override the list::sort(Compare) definition to work with list<pair<int, T> > definition.

//-The Compare Function

template<typename W>
bool weightsort(const pair<int, W> &node1, const pair<int, W> &node2)
{
    return (node1.second <= node2.second);
}


//- Abbreviated class definition containing  STL list definition and call to sort

template<typename T>
class Graph {
    ...
    vector<T> shortest_reach(int startId, T sigWeight) {
        ...
        list<pair<int, T> >                                       frontier;   //-Nodes currently on the Queue to be Explored.
        typename list<pair<int, T> >::iterator      fit;
        ...
            frontier.sort(weightsort);
        ...
    }
    ....
};


$ c++ program.cpp

error: no matching member function for call to 'sort'
            frontier.sort(weightsort);
            ~~~~~~~~~^~~~

usr/include/c++/v1/list:1059:14: note: candidate template ignored:
      couldn't infer template argument '_Comp'
        void sort(_Comp __comp);
             ^
/usr/include/c++/v1/list:1056:10: note: candidate function not viable:
      requires 0 arguments, but 1 was provided
    void sort();
         ^
0
HTML5 and CSS3 Fundamentals
LVL 12
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Dear experts,

In the recent past I have been inquiring or seeking your expert guidance on pursuing a career in Financial Engineering.
I have now reached the stage of working on objects in C++. Once I am thorough with C++ and after having worked on ‘Introduction to C++ for Financial Engineers’ by Daniel J Duffy, I plan to do a project work.
This project work will be done by me while I am in leave.
Can I request if anyone can guide me on selecting a project on Python/C++?
Which platform will be robust for this purpose?
Is there a book I can purchase and practice? Can I use the knowledge I gain by practicing this book in my interview process?

Kindly guide me.
0
I want to create a server(OS: CentOS) which will be acting as an interface to an Android app(client) and the database.

I am not much experienced in programming and I just want a little bit of guidance right now to get started.
I have decided that I want to program the server in C++(though it's not an easy language but I believe there's much more to learn while programming in C++)

The basic functionality I want from my server:
1. It will interact with the app via https.
2. The server and client(app) will communicate via REST APIs.

I want guidance in terms of the most stable and well documented external C++ libraries that I should use to program the above server(I've looked at zmq, libcurl, netlib-cpp but due to my lack of experience I don't even know if these are really related to my problem statement). Thanks in advance. Please feel free to attach any blog/article/video which might be relevant.
0
What is the issue with the above code and how would you fix it?
indentation does not matter in this code, ":=" denotes the substitution, and "=" is the equal comparator.

========
Initial state of an array "a":

[[2, NULL, 2, NULL],
 [2, NULL, 2, NULL],
 [NULL, NULL, NULL, NULL],
 [NULL, NULL, NULL, NULL]]

========
Main function:

FUNCTION foo()
    FOR y := 0 to 3
        FOR x := 0 to 3
            IF a[x+1][y] != NULL
                IF a[x+1][y] = a[x][y]
                    a[x][y] := a[x][y]*2
                    a[x+1][y] := NULL
                END IF
                IF a[x][y] = NULL
                    a[x][y] := a[x+1][y]
                    a[x+1][y] := NULL
                END IF
            END IF
        END FOR
   END FOR
END FUNCTION


What does the foo function do?

How could you make foo more generic? Can we have three possible generalization directions ?
0
I have an issue using an ADOQuery component with C++ builder.
If I execute a simple query "select * from Frames where FrameID = 1934411" the result is no record returned when Frames is a view.
However, if I copy the entire view contents into a table and then run the query against the table then the Record is found ?
The database is a Microsoft SQL Server version 12.0.5207.0

If I run the query on the view or the table using Microsoft SQL Server Management Studio then in both cases the record is returned.

Can this be fixed to use the view ?
0
Hi I am trying make a deep copy of the structure below which will contain the decoded video frames and copy to a new element in a vector without each previous element being overwritten.
The structure below is being populated as the memory in debug mode is increasing as expected with each pass of the while loop.
struct YUV_Buffer
 {
mfxFrameSurface1  *mSurface;
YUV_Buffer(mfxFrameSurface1 *pBuf = { 0 })
    : mSurface(new mfxFrameSurface1[sizeof(mfxFrameSurface1)])
{
    memcpy(mSurface, pBuf, sizeof(mfxFrameSurface1));
}

YUV_Buffer(const YUV_Buffer& YuvBuf) 
 : YUV_Buffer(YuvBuf.mSurface)  
{}

YUV_Buffer& operator = (YUV_Buffer YuvBuf) {

    std::swap(mSurface, YuvBuf.mSurface);
    return *this;
}

~YUV_Buffer() {
        MSDK_SAFE_DELETE_ARRAY(mSurface);
}
  };

Open in new window

I am calling the structure and copying the elements into the vector with each iteration of the while loop "mfxFrameSurface1 pVPPSurfacesOut[nSurfIdxOut]" contains all the information regarding the decoded video frame I need to copy pVPPSurfacesOut[nSurfIdxOut] to the vector mBuffer.push_back(root) using a deep copy so the data that the pointers in the structure are pointing to are also copied but what is actually happening is the last frame processed is overwriting all previous elements in the vector. Each time the loop passes like this: I have removed the code that is decoding each frame as its no relevant I just need to work out why the elements are getting overwritten in the vector
while(1){
std::vector<YUV_Buffer> mBuffer;
YUV_Buffer root(pVPPSurfacesOut[nSurfIdxOut]);
mBuffer.push_back(root);
}

Open in new window

each iteration of the while loop populates pVPPSurfacesOut[nSurfIdxOut] structures which contain pointers with video information like height width buffersize … and the video data its self in a NV12, YUV420 colour space, I need to access each frame from the vector mBuffer but when I try to access the vector mBuffer[0]… Im getting the last frame copyed to the vector.

Regards Nigel
0
Hello , i've the following routine :
int Asio_Send_Pck(int iSendt,int Lsocket,char * Lbuff,int Len)

{

    LSession* iTempLSession = reinterpret_cast<LSession*>(Lsocket);

    boost::asio::async_write(iTempLSession->socket() ,

                              boost::asio::buffer(Lbuff, Len),

                              boost::bind(&LSession::handle_write, 

                              iTempLSession,

                              boost::asio::placeholders::error,

                              iTempLSession->data,

                              iSendt

                              ));

    return 0;

};

Open in new window


But i always get an Invalid Arguments .

Here's my Lsession class :

class LSession
{
public:
  int readlen;
  int userdata;
  int deadtime;
  enum { max_length = 1024};
  char data_[max_length];
  
   LSession(boost::asio::io_service& io_service)
        : deadtime(0), socket_(io_service)
    {
        readlen = 0;
        userdata = 0;
    }

  ~LSession()
  {
	  socket_.close();
  }

  tcp::socket& socket()
  {
    return socket_;
  }

  void start()
  {	  
    socket_.async_read_some(boost::asio::buffer(data_, max_length),
        boost::bind(&LSession::handle_read, this,
          boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred));
  }

  void handle_read(const boost::system::error_code& error,
      size_t bytes_transferred)
  { 
    if (!error)
    {
	
	  try
	  {
	  if(Callback_readdata!= NULL)
	  

Open in new window

0
Hello, are you able to help me in creating a function which will convert an enum value to an actual image in C++?
0
Hello ;
I want to design a GUI.my application is as bellow :
while compiling my program , a first interface is displayed : it is for user authentication, by validating this step ,another interface is displayed :this interface is devided into two screen  show(Splitter with two column) the second interface is combined : a menu , and a tree view .by clicking in one item , a data and controls are shown in the right of interface.
To do this application , did I need for SDI or MDI
Also how to navigate between the two interfaces (the authentication interface and the second interface), should I use two Documents ?
For the first interface , I just want a simple area which display the logo of company and an edit control for tapping the Password. but since compiling the project ,always a classic dialog box is shown (made by Microsoft ).
Is there any idea which clarify my needs.
Kindly.
0
I have a problem whit the LRESULT CALLBACK WndProc,
When i add LPARAM wp the wc give's me a error message, for get the callback functionality when selecting a drop menu item.



main.cpp: In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':
main.cpp:56:24: error: invalid conversion from 'LRESULT (__attribute__((__stdcall__)) *)(HWND, UINT, WPARAM, LPARAM, LPARAM) {aka long int (__attribute__((__stdcall__)) *)(HWND__*, unsigned int, unsigned int, long int, long int)}' to 'WNDPROC {aka long int (__attribute__((__stdcall__)) *)(HWND__*, unsigned int, unsigned int, long int)}' [-fpermissive]
     wc.lpfnWndProc   = WndProc;


#include <windows.h>

void AddMenus(HWND);
HMENU hMenu;

int ID_Save;
int wp;

const char g_szClassName[] = "myWindowClass";

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LPARAM wp)
{
    
    
    switch(msg)
    {
        case WM_COMMAND:
        
        switch(wp)

        {
            case 1:
            MessageBeep(MB_OK);
            break;

        }


        case WM_ACTIVATE:
            AddMenus(hwnd);
            break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,  LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    

Open in new window

0
C++ 11 Fundamentals
LVL 12
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

#include <iostream>
class A {
public:
    int ii = 20;
    A(int i = 200) {
        std::cout << "A() \n";
        ii = i;
    }
    A(const A& obj) {
        std::cout << "Copy Constructor\n";
    }
    A(A&& obj) noexcept {
        std::cout << "A(A&&)\n";
    }
};

void fun(A i) {
    std::cout << "Fun \n" << i.ii << std::endl;
}

int main(int argc, const char * argv[]) {
    fun(A(12)); // Why this is not calling move constructor.
    return 0;
}

Open in new window

0
C++ add menu,
it seems ther is no problem but when the window is created the menu don't show on the screen.
do i need to add a redraw option ?

When i go the a other active window the menu is created. strains.

#include <windows.h>

void AddMenus(HWND);
HMENU hMenu;

int ID_Save;


const char g_szClassName[] = "myWindowClass";

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        
        case WM_CREATE:
            AddMenus(hwnd);
            break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
    
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,  LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;
   
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    
    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", 

Open in new window

0
run in to a trobbel need a littel help to get the window working.

main.cpp: In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':
main.cpp:41:20: error: 'g_szClassName' was not declared in this scope
 wc.lpszClassName = g_szClassName;
                    ^~~~~~~~~~~~~
main.cpp:54:1: error: expected ';' before 'if'
 if(hwnd == NULL)
 ^~
The terminal process terminated with exit code: 1


#include <windows.h>

const char g_sgClassName[] = "myWindowClass";

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
        PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
        
    }
    return(0);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{

WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);


if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);

Open in new window

0
In a CTreeCtrl, does GetChildItem() returns not null, if there is no child?  Is ItemHasChildren() is required? My below code hangs.

HTREEITEM FindTreeItem(HTREEITEM hItem, LPDISPATCH disp)
{
         if (disp == (LPDISPATCH)m_TreeCtrl.GetItemData(hItem))
            return hItem;

      HTREEITEM hChildItem = m_TreeCtrl.GetChildItem(hItem);
      while (hChildItem)
      {
            if (disp == (LPDISPATCH)m_TreeCtrl.GetItemData(hChildItem))
                  return hChildItem;

            HTREEITEM hItemFound = FindTreeItem(hChildItem, disp);
            if (hItemFound)
                  return hItemFound;

            hChildItem = m_TreeCtrl.GetNextItem(hChildItem, TVGN_NEXT);
      }

       return NULL;
}
0
Hello, I'm wondering if anyone has any examples of how to create a C++ Program (the code) to convert:

Feet > Meters
Meters > Feet

Thanks.
0
Since VS 2013 in seems we can use VersionHelpers.h to allow us to ask which version of Windows we are running on.  I looks simple up thru Windows 7 -- but reading the documentation, once we get to Windows 8 or Windows 10, the doc starts talking about the need for a Manifest and mentions GUID.   Can somebody help me understand what is required to get this to work?   My goal: from a C++ program be able to detect if we are running on Windows 10 (or later).   Thanks.
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.