Hello,

I am new to visual C++ and can anyone please kindly help me out this
problem

I had a problem using const string& here is the sample code

class Ctrial1Dlg : public CDialog
{
// Construction
public:
Ctrial1Dlg(CWnd* pParent = NULL); // standard constructor
void getdata();
// Dialog Data
enum { IDD = IDD_TRIAL4_DIALOG };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support


// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedExit();
public:
afx_msg void OnBnClickedCapture();
public:
Device* getDeviceFromUserInput(const DeviceManager& devMgr);
public:
afx_msg void OnBnClickedSave();
public:
int SaveImage(const string &filename);

};

when I had defined SaveImage and passing const string& filename I am
getting two errors

1. error C4430: missing type specifier -int assumed (However I had
used int)

2. error C2143: missing ',' before '&'

Thanks in advance,
Raj.

Re: problem with const string& by MrAsm

MrAsm
Wed May 30 14:00:11 CDT 2007

On 30 May 2007 11:42:14 -0700, bondwiththebest2007@gmail.com wrote:

Hi,

>public:
> afx_msg void OnBnClickedExit();
>public:
> afx_msg void OnBnClickedCapture();
>public:
> Device* getDeviceFromUserInput(const DeviceManager& devMgr);
>public:
> afx_msg void OnBnClickedSave();
>public:
> int SaveImage(const string &filename);

You might also write code like this:

public:
afx_msg void OnBnClickedExit();
afx_msg void OnBnClickedCapture();
Device* getDeviceFromUserInput(const DeviceManager& devMgr);
afx_msg void OnBnClickedSave();
int SaveImage(const string &filename);

For string, try adding this line into StdAfx.h header file of your
project :

#include <string>

then you might want to adjust your SaveImage prototype, like this:

int SaveImage( const std::string & filename );

However, considering that you are in a MFC context, you might want to
use CString class instead of std::string, e.g.:

int SaveImage( const CString & filename );

If you compile your code in Unicode mode, I think you might have
errors when you use std::string (exspecially if you use it in places
where LPCTSTR is required). You don't have these problems with
CString. Of course, feel free to use whatever you like best.

MrAsm

Re: problem with const string& by Ben

Ben
Wed May 30 13:59:01 CDT 2007


<bondwiththebest2007@gmail.com> wrote in message
news:1180550534.003936.316270@p47g2000hsd.googlegroups.com...
> Hello,
>
> I am new to visual C++ and can anyone please kindly help me out this
> problem
>
> I had a problem using const string& here is the sample code
>
> class Ctrial1Dlg : public CDialog
> {
> // Construction
> public:
> Ctrial1Dlg(CWnd* pParent = NULL); // standard constructor
> void getdata();
> // Dialog Data
> enum { IDD = IDD_TRIAL4_DIALOG };
>
> protected:
> virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
>
>
> // Implementation
> protected:
> HICON m_hIcon;
>
> // Generated message map functions
> virtual BOOL OnInitDialog();
> afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
> afx_msg void OnPaint();
> afx_msg HCURSOR OnQueryDragIcon();
> DECLARE_MESSAGE_MAP()
> public:
> afx_msg void OnBnClickedExit();
> public:
> afx_msg void OnBnClickedCapture();
> public:
> Device* getDeviceFromUserInput(const DeviceManager& devMgr);
> public:
> afx_msg void OnBnClickedSave();
> public:
> int SaveImage(const string &filename);
>
> };
>
> when I had defined SaveImage and passing const string& filename I am
> getting two errors
>
> 1. error C4430: missing type specifier -int assumed (However I had
> used int)

You meant std::string. Either fully scope the name, or place a "using
namespace std;" line near the top of your file. "using namespace" shouldn't
appear in .h files though, only .cpp -- inside header files using the fully
scoped name.

>
> 2. error C2143: missing ',' before '&'
>
> Thanks in advance,
> Raj.
>



Re: problem with const string& by beginthreadex

beginthreadex
Wed May 30 14:01:46 CDT 2007

check the cpp for the same signature.

On 30 May 2007 11:42:14 -0700, bondwiththebest2007@gmail.com wrote:

>Hello,
>
>I am new to visual C++ and can anyone please kindly help me out this
>problem
>
>I had a problem using const string& here is the sample code
>
>class Ctrial1Dlg : public CDialog
>{
>// Construction
>public:
> Ctrial1Dlg(CWnd* pParent = NULL); // standard constructor
> void getdata();
>// Dialog Data
> enum { IDD = IDD_TRIAL4_DIALOG };
>
> protected:
> virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
>
>
>// Implementation
>protected:
> HICON m_hIcon;
>
> // Generated message map functions
> virtual BOOL OnInitDialog();
> afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
> afx_msg void OnPaint();
> afx_msg HCURSOR OnQueryDragIcon();
> DECLARE_MESSAGE_MAP()
>public:
> afx_msg void OnBnClickedExit();
>public:
> afx_msg void OnBnClickedCapture();
>public:
> Device* getDeviceFromUserInput(const DeviceManager& devMgr);
>public:
> afx_msg void OnBnClickedSave();
>public:
> int SaveImage(const string &filename);
>
>};
>
>when I had defined SaveImage and passing const string& filename I am
>getting two errors
>
>1. error C4430: missing type specifier -int assumed (However I had
>used int)
>
>2. error C2143: missing ',' before '&'
>
>Thanks in advance,
>Raj.