C++ :: Explicit Conversion From String To Class Reference?

May 10, 2013

following code that I'm reading out of the book "The C++ Standard Library".

class C
{
public:
explicit C(const std::string & s); // explicit(!) type conversion from strings.
...

[Code].....

Now I understand that they are saying that an explicit conversion isn't allowed but what I don't understand is what explicit conversion would be happening if there was one allowed.

Specifically I don't understand the const C & elem syntax. How does this work since the collection holds strings. What would be the syntax for how this:

const C & elem

gets strings. I was thinking it was a class reference that someone how converts to a constructor function pointer or something but i'm really confused.

View 4 Replies


ADVERTISEMENT

C/C++ :: Explicit Specialization Cannot Have A Storage Class

Jan 31, 2013

I am porting code from windows using visual studio to mac with xcode.

Quite a lot of issue have a appeared, which is no surprise, one warning that keeps on appearing is Explicit Specialiszation cannot have a storage class:

enum SortReturnCodeEnum {LOWEST=1, HIGHEST=2, HIGHLOW = 3, IDENTICAL=4};
template<typename tKey>
static SortReturnCodeEnum DefaultCompare(typename ArgType<tKey>::ARGT Value1, typename ArgType<tKey>::ARGT Value2)
{

[Code]....

I could do a #define __GNUC__ but i was checking

View 3 Replies View Related

C++ :: Explicit Linking Of DLL

May 22, 2014

I am working on Explicit Linking of a DLL to an executable. But, when it comes to application, I have some troubles.

1) I try to export a class using C Language approach. (I would ask for other approaches later).

My dll project as follows:

dllmain.cpp
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved

[code]....

2) Related with the question above, what is the best way to provide a "pure" explicit linking? How can I explicitly link a dll without introducing the corresponding .lib and without including the dll's header file?

View 8 Replies View Related

C/C++ :: Number Conversion To String

May 22, 2014

I'm writing a small pice of code that takes numbers and convert it to string. So that's what I got

int main() {
char letter;
char letter1;
char letter2;
cin >> letter;
cin >>letter1;
int sum = letter * 128 + letter1;

[Code] ....

Then it asks the user to enter a letter, say 'w' , which it's value is 119

Then enter another letter, say 'o' which value is 111

then it do the equation, which is take the value of the first letter multiple it by 128 then add it to the value of the second letter.

How can I make it does this process in a For loop, or any kind of loop??

Then I have the second part which is the other way around. That is when the user enter a numbers then the code convert these numbers to a string.

251394404 - "d"
1964018 - "rd"
15343 - "ord"
119 - "word"

so what's happening here is the it divide each time by 128. But I can't do that in a code.

View 3 Replies View Related

C++ :: Conversion Between Char And String

Jun 7, 2013

I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.

I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).

I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.

..
#include <string>
..
char* decryptPwd(char hash[64]);
main () {
string mypwd;
string newmypwd;
if (decryptPwd(mypwd)==newmypwd)

[Code] ...

View 7 Replies View Related

C++ :: Conversion In Types Error (class Involved)

Mar 23, 2014

So I get errors like:

Error1error C2440: 'initializing' : cannot convert from 'const char [4]' to 'Course'
Error2error C2440: 'initializing' : cannot convert from 'int' to 'Course'158
Error3error C2440: 'initializing' : cannot convert from 'const char [6]' to 'Course'158
Error4error C2078: too many initializers158

# include <iostream>
# include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
class Course {
public:
char CourseName[10]; // Array of size 10, 9 characters and 1 null terminator

[Code] .....

And in the /// part I also need to use the dot operator and the arrow operator to print on the screen info about the second and third Courses.

View 3 Replies View Related

C++ :: Float / Double To String Conversion

Oct 22, 2013

I want a code that can convert floating/double value into string/char array(char arr[]) and also it can be run on Boreland C++ 5.02

Here I've a code but it doesn't show all the numbers. Instead, it's showing in exponential form which I don't want!!

int main() {
char* str = new char[30];
float flt = 2.4567F;
sprintf(str, "%.4g", flt );
cout<<str<<endl; //Exponential form even after 6 digits without decimal
return 0;
}

View 5 Replies View Related

C++ :: Numeric Conversion - How To Convert Int Into String

Jun 3, 2013

How to convert int into string ? I had done conversion string to int.

My code :

/*Convert string into int using stringstream */
#include <iostream>
#include <string>
#include "console.h"
#include <sstream>
using namespace std;

[Code] .....

View 3 Replies View Related

Visual C++ :: String To Double Conversion?

Nov 22, 2013

I have the following piece of code:

string ss = findNodeValue( str, "Horizon");
cout << "ss is: " << ss << endl;
double dd = atof( ss.c_str());
cout << "dd is: " << dd << endl;

When the value of 'ss' is printed, I find it prints 1.0, but when the value of 'dd' is printed, it prints 1 whereas it is supposed to print 1.0.

View 2 Replies View Related

Visual C++ :: How To Use ATL 7.0 String Conversion Macros

Feb 5, 2014

I have a problem in using ATL 7.0 string conversion macros.

My codes looks like this, which uses ATL 3.0 string conversion macros in the past:

Void Myfunc()
{
USES_CONVERSION;

LPSTR lpszA;
LPWSTR lpszW;
If (...) {
CString strText;
If (...) {
If (bUnicode)

[Code]...

But since 3.0 macros do not support large strings, I want to switch to 7.0 macros, but have problems. Based on the [URL]... samples, I should declare CT2A pszA(strText) or CT2W pszW(strText) within the if and else bodies, as below:

Void Myfunc()
{
USES_CONVERSION;
LPSTR lpszA;
LPWSTR lpszW;
If (...) {

[Code]...

However, in such a case, after running to the codes using lpszA or lpszW, both CT2A and CT2W will be destructed so lpszA and lpszW will be invalid. How to solve this problem?

View 2 Replies View Related

C/C++ :: Explicit Initialization Of Function Templates

Feb 28, 2013

Why will i use explicit instantiation of a template, for a type? If I do not use explicit instantiation, the template is used to create the necessary function then what is the use of explicit instantiation?

template <class Any>
void Swap (Any &, Any &);
// template prototype  
template <> void Swap<job>(job &, job &);
// explicit specialization for job

[Code] ....

In the above eg. explicit instantiation is done for char type. What is the use of this?? If the compiler can make use of the template to make a fn for char type.

<eg. taken from C++ Primer>

View 4 Replies View Related

C++ :: Deprecated Conversion From String Constant To Char

Aug 6, 2013

I have this old c function that takes as an argument a char*. but my app is written in cpp so i used std::string to store my strings. to pass a char * to the function i tried :

Code:
char *input = new char[args.i.length() + 1];
strcpy(input, args.i.c_str()); and then Code: function (input);
and
function ( (char *)input);

But I still get this warning message which i would like to fix:

Warning: deprecated conversion from string constant to "char*" [-Wwrite-strings]

View 7 Replies View Related

C/C++ :: Deprecated Conversion From String Constant To Char?

Jul 15, 2014

I wrote the following code but i got this error: Deprecated conversion from string constant to 'char*':

#include <iostream>
using namespace std;
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
int Save (int key_stroke, char *file);
void Stealth();

[Code] ....

View 3 Replies View Related

C++ :: Deprecated Conversion From String Constant To Char

Aug 23, 2013

I have 1 struture:

Code:
struct SetText{
int PosX;
int PosY;
char *Text;
};

And heres how i add the values:

Code:
SetText *x=new SetText;x->PosX=5;
x->PosX=6;
x->Text ="hello mother";

why i receive that warning in: x->Text ="hello mother"; ?

"deprecated conversion from string constant to 'char*' [-Wwrite-strings]"

View 6 Replies View Related

Visual C++ :: Pointer / Reference To Class Within Class?

Oct 3, 2012

I have encountered a problem I can't see to solve. I want to access a function and can't seem to find the right combination to get me there. Here is what I am looking at:

CFoo1::CFoo2::GetStrDataC(int nRow) const

How do I call the GetStrDataC function from another class?

View 6 Replies View Related

C++ :: Array Base Stack Class - Infix To Postfix Conversion

Feb 4, 2014

Array based stack class. So i am having a problem, i do not understand how to convert an infix notation into a postfix notation from a txt file. The infix expressions are stored in a text file. for example inside the text file is

6+9
2+7*8
(1+5)*3
5+(6-2)*((2-8)

at the moment my header file is

#ifndef STACKS_H
#define STACKS_H
#include <iostream>
using namespace std;
const int STACKS_CAPACITY = 128;
typedef int StacksElement;

[Code] ....

but how to make it convert the into postfix...

View 3 Replies View Related

C++ :: Using Fgets To Read In A String - No Conversion Function Error

May 27, 2013

I am trying to use fgets to read in a string, but keep getting a "no conversion function from std::string to char" error.

View 2 Replies View Related

C/C++ :: Unlimited Number Of Arguments - Float To String Conversion

Mar 21, 2015

So, I'm supposed to do : Create a function with unlimited number of arguments, which forms a dynamic string based on the following form (%d, %s, %f, %lf, %c), with the following prototype:

char*create(char*form, ...);

The function is supposed to have the following output:

create("Peter is %d years old and is in %s-%c class.",7,"second",'A');
-> Peter is 7 years old and is in 7-A class.
create("His GPA is %lf.",4.96);
-> His GPA is 4.96.
create("His favourite subject is math!");
-> His favourite subject is math!

I've managed to do the following :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
char *create(char *form, ...) {
char *res =(char*)calloc(1,1),*pos_int,*pos_float,*pos_str,pos_char,*pos_long;

[Code] ....

The part with %d and %s string was not that hard, but now I'm supposed to convert %f and %lf to string, I've tried using sprintf but I've had no luck so far, another problem is the fact that I've gotta use lists to complete the task. I've been trying to convert float to string for the past 2 hours, but I'm drawing a blank now.

View 4 Replies View Related

C/C++ :: Conversion Of Negative Integers To String Without Using Atoi Function

Sep 21, 2014

char intToStr(int a) {
int n, i, j, sign, set;
char r[10], s[10];
if (a[0] == '-')
sign = -1;
if (sign == -1)

[Code] ....

I have doubt at the time of handling of negative numbers at the time of converting to string ....

View 2 Replies View Related

C++ :: Threads Giving Error - Call Of Object Of A Class Type Without Appropriate Operator Or Conversion

Jan 27, 2015

I made a simple binary tree then decide to try out threads too. I got the following error:

call of an object of a class type without appropriate operator or conversion

Code:
#include "Tree.h"
#include <iostream>
#include <thread>
void main(void){

[Code] ....

I am having a hard time figuring out why the error exists. I tried adding the new operator but that did not work.

View 11 Replies View Related

C++ :: Pass Class Object By Reference

Jun 25, 2013

I am having trouble working with third party dll's, libs and header files. I am trying to call a function.here is the function that is suppose to be called.

bool COAuthSDK::GetRequestToken(CClientDetails &objClientDetails)

it has this info of what it needs :

Name IN/OUT Description
m_environment IN Optional. Possible values are SANDBOX (default) and LIVE.
m_strConsumerKey IN OAuth consumer key provided by E*TRADE
m_strConsumerSecret IN OAuth consumer secret provided by E*TRADE
m_strToken OUT Returned by the function if successful
m_strTokenSecret OUT Returned by the function if successful
m_strCallback IN Optional; default value is "oob"

here is the COAuthSDK header

#ifndef _OAUTHSDK_H_INCLUDED_
#define _OAUTHSDK_H_INCLUDED_
#include "ETCOMMONCommonDefs.h"
#include "ETCOMMONOAuthHelper.h"
using namespace std;

[code].....

when I try to build the function it says that its in the dll's so I know I have to call it.here is the link to the build site if needed URL....

View 1 Replies View Related

C++ :: Undefined Reference To Class Definition

Aug 4, 2013

I have successfully built OGDF under directory undefined reference to /home/vijay13/Downloads/OGDF-snapshot/

I have following code in test.cpp under directory /home/vijay13/Downloads/ :

#include <ogdf/basic/Graph.h>
#include <ogdf/fileformats/GraphIO.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
using namespace ogdf;

[Code] .....

while compiling as following :

vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/

I am getting following error:

vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/
/tmp/ccPE8nCu.o: In function `main':
test.cpp:(.text+0x26): undefined reference to `ogdf::Graph::Graph()' ...................... so on

View 2 Replies View Related

C++ :: Pass Class Object By Reference?

Mar 17, 2014

I'm trying to pass a class object by reference.

total = mathfunction(i);
}
double mathfunction(retirement& j)
{
double R = 0.00, m = 0.00, r = 0.00, t = 0.00, totaled = 0.00,
numerator = 0.00, denom = 0.00, temp = 0.00;

[Code]....

I only tried to pass by reference because I figured passing by value would be a larger pain in the neck.

View 1 Replies View Related

C++ :: Assignment Operator For A Class With Reference

Mar 6, 2014

Class A
{..........}

Class B:
{....
private U& u;}

I need to write the copy constructor and assignment operator for Class B above. Copy would look something like this:

B::B(conts B& bo): u(bo.u){}

is this correct ... and how will the assignment operation look like??

View 3 Replies View Related

C++ :: Reference Semantic For Pimpl Class?

Jun 18, 2012

I have a basic class with a pimpl, with agressive instantiation:

Code:
class MyClassImpl;
class MyClass {
public:
MyClass() : pImpl(new MyClassImpl) {}

[Code] ....

Classic/Standard. However, I do hate having to use pointer semantics for all of my operations. So I thought: If I never ever manipulate the actual pointer itself, why not just keep a reference?

Code:
class MyClassImpl;
class MyClass {
public:
MyClass() : impl(*new MyClassImpl) {}
~MyClass(){delete &impl;}
private:
MyClassImpl& impl;
};

The only downside that I see, is that I can't swap or move, but this particular object is not meant to be swapped or moved.

View 4 Replies View Related

C++ :: Inherited Class Constructor - Undefined Reference

Jun 18, 2013

I have three classes 1 base and two inherited.. problem is when I try to initialize the it says undefined reference to vtable constructor.

Code:
#ifndef QUOTE_H_INCLUDED
#define QUOTE_H_INCLUDED
#include <string>
using namespace std;

[Code] ....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved