main.cpp
,
|
|
header.cpp
and also corresponding header.h
.
|
|
|
|
|
|
|
|
|
|
g++ main.cpp func.cpp -o overload
./overload
.
To compile I would do: g++ main.cpp func.cpp -o overload |
|
|
|
|
|
|
func (type1)
in both cases, same data type argument but different return type. The compiler doesn't allow this... and throws some strange "ambiguating new declaration". I don't know how to proceed. One ugly solution will be to insert another fake argument in one of the func
s... so that the arguments are different, but I don't like it.
One ugly solution will be to insert another fake argument in one of the func s... so that the arguments are different, but I don't like it. |
string
(s), an std::string
and another CERN's ROOT string called a TString
(https://root.cern.ch/doc/v608/classTString.html). They both keep occuring all the time and I need play around so I need to overload one function name that can take both kinds of strings etc... just like we overload an addition (of two numbers double or int ) function when learning c++ for the first time.
I have two kinds of string(s), an std::string and another CERN's ROOT string called a TString |
TString
for everything? Can TString
be constructed from a std::string
? Why is there a perception that you have to use both types? TString
type.
std::string
, it's the output that differ. Currently I am relying on std::stringstream
to convert one to the other kind as a temporary solution.
alias g++='g++ -Wall -Wextra -Werror -pedantic -std=c++14'
so sometimes forget to mention.
But I need same input type, both std::string, it's the output that differ. |
QString
. One does everything with that and doesn't use std::string
at all.
there may be no need to use both types... in Qt, there is QString. One does everything with that and doesn't use std::string at all. |
std::string
already in QString
, in the latter case, maybe it's also true for TString
but I am not an expert and I don't know how various member
s of std::string
translate to the TString
, so my solution will be the conversion. My situation is the following: *.root
file it uses the syntax Tfile.Open(TString);
and doesn't accept std::string, but I need std::string
for many other things because I am not interested to work entirely within CERN's ROOT, I am just interested in a few of their libraries and because I need to analyze data stored in *.root
files, I do need std::string
for most part. Hence my workaround will be to use std::stringstream
to convert one type to the other and hence I can always work with std::string
.
Hence my workaround will be to use std::stringstream to convert one type to the other and hence I can always work with std::string. |
c_str()
on a TString
yet but my guess is that compiler will complain. Consider the following program that takes a filename "file.root":
|
|
|
|
|
|
my interpretation of this would be that either Qt users use a conversion rule of some kind or they have all the features of std::string already in QString , in the latter case, maybe it's also true for TString but I am not an expert and I don't know how various members of std::string translate to the TString , so my solution will be the conversion. |
QString |
std::string
. Qt has technical reasons for doing so, mainly to do with Qt's use of the Meta Object Compiler (MOC)TString
from a std::string
. And there is lots of functionality in TString
, as I asserted earlier, you can use that almost exclusively.
|
|
|
|
|
|
TheIdeasMan (4983) Your code compiles for me, you didn't include <string>. As I keep saying, there is no need for function overloading at all. |
#include <whatever else needed>
that includes <string>
too.Neither is probably a good way to learn C++ and then adapt without a clear understanding of C++ (maybe even C). |
read about function mangling in C++ |