Which one is the a valid function prototype? Is it C only?
A. template void Display(std::vector& obj);
B. template void Display(std::vector& obj);
C. template void Display(std::vector& obj);
D. template void Display(std::vector& obj);
E. template void Display(std::vector& obj);
一直用Java, 现在需要突击学下c++。随便找了本老书:
c++, An Introduction to computing 1998 by Adams, Leestma and Nyhoff
可是把里面的第一个源程序放到学校的unix上运行gcc sample.cpp,
竟然出了一堆错。源程序很简单:
#include
using namespace std;
int main() {
cout << "hello";
}
出错信息:
Undefined first referenced
symbol in file
std::basic_string, std::allocator >::
operator[](unsigned int) const/var/tmp//cceUTnka.o
std::cout /var/tm
http://www.acceleratedcpp.com/details/msbugs.html
Chapter 12
Similar to the problems in Chapters 6 and 8, where VC++ 6.0 fails to include
the character classification functions (isalpha, isalnum, isspace etc.) as
part of the std namespace, it also fails to include the strlen function in
std. The workaround is analogous: Omit the qualification of std::strlen.
For example, in the Str constructor that takes a const char*:
#ifdef _MSC_VER
std::copy(cp, cp + strlen(cp), std::back_inserter(data));
#el
☆─────────────────────────────────────☆
campos (campos) 于 (Mon Sep 26 21:24:28 2005) 提到:
in STL
how to define/use set of set
std::set setname;
doesn't work
☆─────────────────────────────────────☆
campos (campos) 于 (Mon Sep 26 21:37:58 2005) 提到:
ft
原来应该写成
std::set > setname;
Does the gcc compiler optimize the following code?
std::vector v(5);
std::vector::iterator it;
for(it = v.begin(); it != v.end(); it++)
Or is it faster to do this:
std::vector v(5);
std::vector::iterator it;
std::vector::iterator end(v.end());
for(it = v.begin(); it != end; ++it)
Note that the temp variable end, and the preincrement of it.
I was reading Exceptional C++ and it says the second way is faster, but I'm
wondering if the comipler has gotten better since the boo
Which allocator member function do standard containers use to acquire
storage for their elements in C++?
A. std::allocator<>::make(size_t)
B. std::allocator<>::new(size_t)
C. std::allocator<>::malloc(int)
D. std::allocator<>::allocate(size_t)
E. std::allocator<>::acquire(size_t)
我只知道D,allocate是allocator 的member function.
多谢
下面的代码有时候会crash在LINE_A或LINE_B这两行,哪儿不对?
class A{
//...
map m_int2StrMap;
//...
void problematic(){
//...insert and erase of m_int2StrMap are involved
char temp[6] = {0};
int key = 12345;
//...temp's elements and key might be changed
map::iterator iter = this->m_int2StrMap.find(key);
if(iter != this->m_int2StrMap.end())
{
/*LINE_A*/ this->m_int2StrMap.erase(iter);
... 阅读全帖
in c++ 11:
template
class Holder {
std::static_assert(!std::is_copy_constructible::value);
std::static_assert(std::is_move_constructible::value);
Baton m_baton;
void Receive(Baton &&b) { m_baton = std::move(b); }
}
any Baton passed that is copy constructible, or is not move constructible
should cause a compilation error.
disclaimer: I have not used these traits, so you probably need to fiddle to
make it work.
anyhow check out type_traits. I did similar things b... 阅读全帖
I defined a random number generator class norm, I would like to define a std
::vector of norm. However it did not work.
I got "Debug Assertation Failed" after the first of for loop.
Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse).
Any input are appreciated. Thanks!
code:
unsigned long seeds[]={123, 345, 356};
std::vector myseeds(std::begin(seeds), std::end(seeds));
std::vector mynorm;
for(auto it=myseeds.begin(); it!=myseeds.end(); ++it)
{
mynorm.push_back(norm(*it));
... 阅读全帖
销售状况 http://www.novelrank.com/asin/1591845521
Bend, Not Break:A Life in Two Worlds
Amazon.com
Last Sale: 2 hours
February Sales: 80
January Sales: 595
Current Rank: 1,408
Sales Rank Stats chevron down
Best Rank: 24
Worst Rank: 453,535
Average: 57,555
Std Dev: 93,396
Amazon.co.uk
Last Sale: 69 days,
21 hours
February Sales: 0
January Sales: 0
Current Rank: 436,631
Sales Rank Stats chevron down
Best Rank: 206,764
Worst Rank: 206,764
Average... 阅读全帖
看来国女完败了,连性病都比白女多
But we found that Asian American young women are at risk of high STDs. For
instance, Asian American women had a higher prevalence of STDs than White
women in both 1995 (10.4% vs. 7.7) and 2001 (13.5% vs. 8.3%). The incidence
of STDs (not diagnosed with STDs in 1995, but developed STIs in 2001) among
Asian American women was also higher than that of White women."
But we found that Asian American young women are at risk of high STDs. For
instance, Asian American women had a higher prevalence of STDs than White
women in both 1995 (10.4% vs. 7.7) and 2001 (13.5% vs. 8.3%). The incidence
of STDs (not diagnosed with STDs in 1995, but developed STIs in 2001) among
Asian American women was also higher than that of White women."
[url=http://www.bu.edu/phpbin/news-cms/news/?dept=692&id=52827]http://www.bu.edu/phpbin/news-cms/news/?dept=692&id=52827[/url]
波士顿大学的... 阅读全帖
【 以下文字转载自 JobHunting 讨论区 】
发信人: justicezyx (just), 信区: JobHunting
标 题: Re: 大家看看一个自称狗家码农写的代码 (转载)
发信站: BBS 未名空间站 (Sun Nov 19 17:50:19 2017, 美东)
几个细节,跟google c++代码要求差别比较大。
这个代码我是看不懂在做什么。
#include
#include
#include
using namespace std;
// using declarations on namespace is banned in google c++ code
class Solution
{ // this is not the style used in google, if you write c++ in google, I
feel very difficult to believe that you can resist the muscle memory and
uses a differ... 阅读全帖
Not necessarily, but unlike Asian women in USA, white women don't have to go
after assholes to survive, so even if white women have 10 sexual partners
and Asian women in USA have only 5, chance of getting STDs is still lower
for white women. This also explains why in Asian nations Asian women don't
have significantly higher STD infection rate than Asian men.
That general who claims that Asian get STDs from hookers has gone too far.
It is not because Asian men in Asian nations are bad, it because... 阅读全帖
原题也是在这个版上有人发的C++的其中一题,已copy下来:
class Person{
public:
Person(const char* szName);
const char* GetName() const;
/*put a function here*/
private:
char *m_szName;
};
int main()
{
Person person("John");
std::cout << Person;
return 0;
}
Referring to the sample code above, which one of the following member
functions do you add at the comment to support std::cout << person
statement?
A. std::string operator() { return GetName(); }
B. std::string ToString() { retur
Q1) Which of the following general functions gives a pointer to the
immediate
base class of a derived class, i.e. the direct parent class?
A) parent()
B) super()
C) base()
D) This function does not exist.
我好像选了super(), 这个java里有,c++里有没有啊?
Q2) What is the problem with the following code snippet?
class myclass;
myclass* pmc = new myclass();
free(pmc);
A) The problem is that releasing memory with "free" is possible only if the
memory was allocated with "malloc".
B) The problem is that "free" ... 阅读全帖
Good explanation! Very straightforward.
What about next_combination()? There is some code online, no straightforward
explanation though. http://stackoverflow.com/questions/127704/algorithm-to-return-a
template
bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
/* Credits: Mark Nelson http://marknelson.us */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator i1 = first;
Iterator i2 = last;
++i1;
if (la... 阅读全帖
//2. Given an array of 'n' random integers. Given an integer k<=n. Find the
k
//numbers such that the minimum difference of all the possible pairs of k
//numbers is maximum (maximum among other minimum differences for various
//possible selections of k numbers ).
//
void FindMaxMinGapSubArray(int *in, int len, std::vector *out, int k){
if (!in || len < 1 || !out || len < k || k < 2)
return;
std::sort(in, in + len);
// 1 2 3 4 5
int max_gap = (*(in + len - 1) - *in) /... 阅读全帖
有没有办法强制基类中定义的pure virtual function在所有的继承类中实现
For example:
class A
{
public:
virtual void func() = 0;
};
class B: public A
{
public:
void func() { std::cout<<"In B"<
};
class C: public B
{
public:
void func() { std::cout<<"In C"<
};
class C中也必须实现 func,否则报错
有没有办法强制基类中定义的pure virtual function在所有的继承类中实现
For example:
class A
{
public:
virtual void func() = 0;
};
class B: public A
{
public:
void func() { std::cout<<"In B"<
};
class C: public B
{
public:
void func() { std::cout<<"In C"<
};
class C中也必须实现 func,否则报错