|
What is the difference between
private void DoSomething(int value) { value++; }
and
private int DoSomething(int value) { return value++; }
when used as either
DoSomething(value);
versus
value = DoSomething(value);
Started by JMs on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Try it: if you execute your first example, after DoSomething....
Value = DoSomething(value); std::cout<<value<<std::endl; DoSomething(value); std::cout< that exists inside the scope of DoSomething().
|
|
On Fri, 16 Jan 2009 14:24:59 -0800, Carl Forsman <fatwallet951@yahoo.com
are they basically the same?
except portablity where CString is only microsoft?
Started by Carl Forsman on
, 13 posts
by 6 people.
Answer Snippets (Read the full thread at omgili):
4) CString has an LPCTSTR (const TCHAR *), instead
you must ... .
3) CString is reference counted, instead I believe that std::string is not.
Something like
typedef std::basic_string< TCHAR
2) CString offers useful methods like Left.
|
|
Class A{ A(int a = 5){ DoSomething(); A(); } A(){...} }
Can the first constructor call the second one?
Started by MainID on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I_,j_; }; int main() { A a1(10,11), a2(10); std::cout << a1.i_ << ", " << a1.j_ << std::endl << a2.i_ << ", " << a2.j_ << std::endl; return 0; }
*Hell to decide which construcotr to....
|
Ask your Facebook Friends
|
Hi,
I want to sort points_vec vector as shown in the pseudocode below. I want to sort this vector, by a coordinate value like x or y or z
class A{ std:vector<double*> points_vec; void doSomething(); }
Then, in method A::doSomething, I want sort ...
Started by memC on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
; } class A { std::vector<Point> pts_; void doSomething() { sort(pts_.begin(), pts_.end Point3D class not a couple doubles Define the less then operator for Point3D Just call std::sort(points points here } };
And use like:
....
|
|
Currently, I have this code to prepend a "tag" to an exception message which gives me a very light version of a stack trace:
try { doSomething(); } catch (std::exception& e) { int size = 8 + _tcslen(e.what()); TCHAR* error = new TCHAR[size]; _sntprintf...
Started by Etan on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Why don't you use std::string?
try { doSomething(); } catch (const std::exception& e) { throwwhat about something like this:
throw std::exception(std::string("myTag: ").append(e.what()).c_str compile in ....
Of string.
|
|
I have a templated class defined (in part) as
template <class T> MyClass { public: void DoSomething(){} };
If I want to call DoSomething from another class, but be able to do this for multiple 'T' types in the same place, I am stuck for an idea ...
Answer Snippets (Read the full thread at stackoverflow):
Class MyClass : public Base { public: void DoSomething(){} }; std::vector<Base *> objects this:
class Base { public: virtual ~Base(){} virtual void DoSomething() = 0; } template <class T>.
|
|
In the past I've used the bind1st and bind2nd functions in order to do straight forward operations on STL containers. I now have a container of MyBase class pointers that are for simplicities sake the following:
class X { public: std::string getName()...
Started by RC on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Struct callDoSomething { void operator()(const X* x){ StaticFuncClass::doSomething(x->getName X* x ) { StaticFuncClass::doSomething(x->getName(), funcrReturningString() ); } for_each.
|
|
I am familiar with C++ RTTI, and find the concept interesting.
Still there exist a lot of more ways to abuse it than to use it correctly (the RTTI-switch dread comes to mind). As a developer, I found (and used) only two viable uses for it (more exactly...
Started by paercebal on
, 10 posts
by 10 people.
Answer Snippets (Read the full thread at stackoverflow):
Right : top { std::string name; right() : name("plonk") { } }; struct bottom : left, right { }; bottom.
|
|
I'm quite confident that globally declared variables get allocated (and initialized, if applicable) at program start time.
int globalgarbage; unsigned int anumber = 42;
But what about static ones defined within a function?
void doSomething() { static ...
Started by Owen on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
This, among other things, lets you initialize globally.
Lt;string> using namespace std; class test { public: test(const char *name) : _name(name) { cout doSomething() is first called?
Yes, it is.
|
|
I think you might dislike C++ crappy features but I just want to know what is virtual base class and what it means:
Let me show an example:
class Foo { public: void DoSomething() { /* ... */ } }; class Bar : public virtual Foo { public: void DoSpecific...
Started by popopome on
, 13 posts
by 10 people.
Answer Snippets (Read the full thread at stackoverflow):
Include "stdafx.h" #include <iostream> using namespace std; class Foo { public: void DoSomething DoSomething() = 0"
A virtual base class is a class that cannot be instantiated : you cannot create direct.
|