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.
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:
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?
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)
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.
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; }
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:
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?
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?
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.
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]
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?
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;
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!
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.
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.
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"
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
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.