带指针类的初始化

·
notes no tag March 15, 2022

尤记得侯捷老师一上来就自带大佬腔调讲类的模版,讲完模版就讲类的口吻。

我在c++起步的时候,是理解不了他的课程的,至于网上那么多推荐他的课程给入门者的帖子,没必要迷信。

今天无意中写了如下代码:

class test_class {
public:
    test_class *front;
};

int test() {
    test_class Q;
}

按照正常逻辑初始化Q在栈上,没毛病吧。

编译器没说啥,警告都没(Apple clang version 13.1.6 (clang-1316.0.21.2)),IDE提示说Clang-Tidy: Uninitialized record type: 'Q'

之前遇到过这个小的提示没放在心上,今天查了查看确实还有说法。

clang官方文档大概是这个意思:这个问题的关键在于check flags,按我的理解应该翻译如下“检查标记用户定义的构造函数”。该检查标志着用户定义的构造函数定义没有初始化所有默认构造会留下未定义状态的字段,例如,没有用户提供的默认构造函数中至少包含一个这样的类型的内置物、指针和记录类型。如果这些字段没有被初始化,构造器将使一些内存处于未定义状态。

对于C++11,它建议修复添加类内字段初始化器。对于旧版本,它将字段初始化器插入构造函数初始化器列表中。它还将初始化任何需要在构造函数初始化器列表中归零的直接基类。

该检查将构造函数主体中的字段赋值考虑在内,但对于在构造函数主体中调用的方法中初始化的字段会产生误报。

该检查还标记了具有自动存储期限的变量,这些变量具有没有用户提供的构造器的记录类型,并且没有被初始化。建议的修复方法是,对于C++11及以后的版本,通过{}对变量进行零初始化,或者对于较早的语言版本={}。

总之:这个警告提醒你,你可能有未初始化的成员变量。

想起之前的一个new操作符的问题,也是build阶段没有报错,但是IDE提示了警告,算是对语法的警示吧。

anyway这个ide是clion,这玩意几乎每个单词底下都画满了警示线,甚至提示你这个函数可以弄成静态的,看起来真实搞死强迫症,对养成好的编程习惯来说还是很有力的工具的。

啊,没问题的代码不用我说应该知道是什么样子了吧。

class test_class {
public:
    test_class *front;
};

int test() {
    test_class Q{};
}

讲真,侯捷老师的课还是要好好看,这个知识点他第一节课就说过了。

  • new和malloc关键字
  • c++之指针和引用作为函数参数传递时的区别

已有 71 条评论
  1. agevose

    cialis packaging [url=https://buycialikonline.com]cialis 20mg[/url]

    agevose July 29th, 2022 at 07:37 pm回复
  2. floucoura

    ivermectine mylan Combining Forms COMBINING FORM MEANING COMBINING FORM MEANING amnio myomo bartholino nati cephalo obstetro cervico oligo chorio choriono oo colpo oophoro culdo ovo episio ovario galacto ovulo gyneco perineo hystero phoro lacto pyo mammo salpingo masto utero meno vagino metro metrio vulvo myo Prexes PREFIX MEANING PREFIX MEANING bi oxy dys peri endo pre in primi intra pseudo multi retro nulli uni FEMALE REPRODUCTIVE SYSTEM Sufxes SUFFIX MEANING SUFFIX MEANING arche plasty cyesis rrhagia dynia rrhaphy ectomy rrhea exion salpinx genesis scopy gravida stenosis itis stomy pareunia tocia parous tomy plasia version Match the following diagnostic procedures with their descriptions.

    floucoura August 18th, 2022 at 03:37 pm回复
  3. bockege

    99, 200 Pills 2 buy cialis 20mg Sometimes, the delivery may be delayed as your parcel may be arrested and thoroughly examined

    bockege September 1st, 2022 at 06:40 am回复
  4. sypeunemy

    best site to buy priligy Prior approval from a doctor is also needed

    sypeunemy September 3rd, 2022 at 10:24 am回复
  5. Blavazy

    buying cialis online safely Your physician may not recommend certain erectile dysfunction medications if you are already on medication for cardiovascular disease

    Blavazy September 5th, 2022 at 08:30 am回复
  6. nictraimi

    This is a summary and does NOT have all possible information about this product tadalafil cialis from india Brand Vidalista 60Mg

    nictraimi September 7th, 2022 at 10:58 am回复
  7. Abedlip

    signs clomid is working Wild yams are said to hyper-stimulate the ovaries, resulting in the release of more than one egg for ovulation.

    Abedlip September 10th, 2022 at 08:31 am回复
  8. estuarm

    Like with any other OTC over the counter medication we suggest that you confirm it s use first with your doctor. nolvadex for gyno 2008; 89 151 156.

    estuarm September 13th, 2022 at 10:34 am回复
  9. hoargorgo

    doxycycline brand name He has no equity interest in either Functional Nutriments, LLC or Apocaps.

    hoargorgo September 17th, 2022 at 01:44 am回复
  10. Jateemi

    She thought that using lots of sunscreen way more than usual would prevent it torsemide to lasix conversion calculator

    Jateemi October 7th, 2022 at 01:27 pm回复
  11. toinnafar

    clomid ovulation calculator Gynecomastia in prepubertal and pubertal men

    toinnafar November 18th, 2022 at 03:37 pm回复
  12. coancepaL

    Each woman has to decide what works best for her, her lifestyle, and her body lasix blood thinner com 20 E2 AD 90 20Sainsbury 20Viagra 20 20C 27est 20Quoi 20Le 20Viagra 20En 20Arabe c est quoi le viagra en arabe In clips that went viral, June Shannon, now 33, got even more attention for extreme coupon clipping, bulk paper towel buying, belching and giving Alana Гў go go juiceГў Гў a mixture of Mountain Dew and Red Bull Гў to boost pageant performance

    coancepaL November 19th, 2022 at 05:00 am回复
  13. stoowatry

    Nutritional Information 150 calories, 7 g total fat, 15 g total carbohydrate, 9 g protein per serving buy stromectol for humans in mexico

    stoowatry November 21st, 2022 at 05:58 pm回复
  14. KwivClelm

    hi opp ggeis 2022 ert go fi

    KwivClelm December 4th, 2022 at 03:43 pm回复
  15. nabadoria

    K program which offered monetary incentives to drug and alcohol abusers to participate in long term or permanent birth control cheapest propecia

    nabadoria December 11th, 2022 at 10:45 am回复
  16. Qebsketa

    furosemide in congestive heart failure aldactone e lasix mekanisme furosemide https://lasixyvf.com/

    Qebsketa December 11th, 2022 at 10:49 pm回复
  17. Ebdsketa

    pioglitazone metformin glibenclamide glucophage ne ise yarar contraindication metformin use https://metforminukx.com/

    Ebdsketa December 11th, 2022 at 11:58 pm回复
  18. Tiisketa

    lisinopril dosage rxlist hydrochlorothiazide and herbs taking extra lisinopril https://lisinoprilseh.com/

    Tiisketa December 12th, 2022 at 12:27 am回复
  19. PrannaBic

    Mikati None how soon after surgery can i take viagra More details regarding patient and tumor characteristics as well as the treatments received are given in Table 1

    PrannaBic December 12th, 2022 at 03:01 am回复
  20. KwwbClelm

    flagyl gives yeast infection flagyl green urine metronidazole and bacterial overgrowth https://flagylaqa.com/

    KwwbClelm December 12th, 2022 at 08:14 am回复
  21. Asapsype

    abnormal bleeding while on tamoxifen buy nolvadex for gyno tamoxifen for muscles building https://nolvadexsrm.com/

    Asapsype December 12th, 2022 at 06:49 pm回复
  22. Wndyembap

    can you have alcohol with atenolol atenolol 50mg ems can i take expired atenolol https://tenorminscx.com/

    Wndyembap December 12th, 2022 at 10:49 pm回复
  23. JnwDillclelm

    trazodone amount to take celexa and trazodone forum does trazodone make you hungry https://trazodonesuc.com/

    JnwDillclelm December 12th, 2022 at 11:20 pm回复
  24. Jwbfembap

    bactrim cats fever with bactrim bactrim ds shaking https://bactrimrol.com/

    Jwbfembap December 13th, 2022 at 06:38 am回复
  25. brumeno

    All papers were assessed for the quality of the evidence utilising Grading of Recommendations Assessment, Development and Evaluation GRADE methodology 13 consequences levitra

    brumeno December 14th, 2022 at 03:10 am回复
  26. Arressick

    how much viagra should a woman take Morris as Premature Ovarian Failure

    Arressick December 15th, 2022 at 03:39 pm回复
  27. Plaippids

    If you have any reason to think you are pregnant; stop taking this medication at once and contact your care team cialis cheapest online prices

    Plaippids December 16th, 2022 at 05:50 am回复
  28. Qewsketa

    lyrica anderson net worth 2020 pregabalin withdrawal matilda lyrica https://lyricaxol.com/

    Qewsketa December 17th, 2022 at 11:11 pm回复
  29. Ebdsketa

    losing weight on glucophage precio glucophage mexico metformin robb wolf https://metforminukx.com/

    Ebdsketa December 18th, 2022 at 12:17 am回复
  30. Tiinsketa

    gabapentin tagamet neurontin vademecum neurontin tabl https://gabapentinujv.com/

    Tiinsketa December 18th, 2022 at 12:47 am回复
  31. JuuiDillclelm

    valtrex jp valtrex exercise valtrex xr https://valtrexujd.com/

    JuuiDillclelm December 18th, 2022 at 08:43 am回复
  32. Wndyembap

    walgreens atorvastatin irbesartan atorvastatin lipitor pakistan https://tenorminscx.com/

    Wndyembap December 18th, 2022 at 02:39 pm回复
  33. Asapsype

    vaistai tamoxifen nolvadex d tamoxifen nolvadex creme https://nolvadexsrm.com/

    Asapsype December 18th, 2022 at 07:10 pm回复
  34. Jdsembap

    lipitor farting atorvastatin acs lipitor dairy https://lipitorxer.com/

    Jdsembap December 18th, 2022 at 10:30 pm回复
  35. Qewsketa

    pregabalin sexual side effects another name for pregabalin pregabalin withdrawal https://lyricaxol.com/

    Qewsketa December 19th, 2022 at 03:48 pm回复
  36. Tiinsketa

    neurontin graviditet neurontin hypersomnia gabapentin tremors https://gabapentinujv.com/

    Tiinsketa December 19th, 2022 at 05:25 pm回复
  37. Quusketa

    cialis for sell cialis dosage 20mg cialis not working first time

    Quusketa January 19th, 2023 at 06:25 pm回复
  38. Ebxdsketa

    how much is viagra in mexico buy generic viagra online in india sildenafil best price

    Ebxdsketa January 19th, 2023 at 07:29 pm回复
  39. Tnntsketa

    tadalafil online canadian pharmacy tadalafil 20 mg why buy cialis. com

    Tnntsketa January 19th, 2023 at 07:41 pm回复
  40. JrnDillclelm

    viagra vs cialis forum cialis erectile dysfunction cialis for sale payment paypal

    JrnDillclelm January 20th, 2023 at 05:02 am回复
  41. Woolembap

    viagra medication cheap sildenafil 50mg uk sublingual viagra

    Woolembap January 20th, 2023 at 08:59 am回复
  42. Jdnsembap

    cialis professional review cheapest tadalafil tablets how long after taking cialis can i take viagra

    Jdnsembap January 20th, 2023 at 04:15 pm回复
  43. Avxepsype

    best generic viagra safe buy viagra online where to buy genuine viagra online

    Avxepsype January 20th, 2023 at 08:52 pm回复
  44. Qubsketa

    fda approved canadian pharmacy Effexor costco pharmacy viagra prices

    Qubsketa January 21st, 2023 at 02:05 am回复
  45. Eexdsketa

    finpecia uk pharmacy indian pharmacy soma canadian pharmacies cipro hc suspension 0.2-1%

    Eexdsketa January 21st, 2023 at 03:05 am回复
  46. Tujsketa

    pharmacy online shopping effexor xr online pharmacy canadian government approved pharmacies

    Tujsketa January 21st, 2023 at 03:21 am回复
  47. JbqDillclelm

    protonix pharmacy pharmacy orlando cheapest canadian pharmacy for viagra

    JbqDillclelm January 21st, 2023 at 07:13 pm回复
  48. Worolembap

    tylenol 3 canada pharmacy provigil at canadian pharmacy costco pharmacy prices viagra

    Worolembap January 22nd, 2023 at 07:38 am回复
  49. Qemmsketa

    sildenafil generic cost sildenafil price comparison in india viagra without prescription uk

    Qemmsketa January 26th, 2023 at 03:51 am回复
  50. Tnfxsketa

    generic cialis 5mg tadalafil 5mg best price difference between tadalafil and cialis

    Tnfxsketa January 26th, 2023 at 05:05 am回复
  51. Jnebembap

    clozaril pharmacy registration legitimate online canadian pharmacies humana online pharmacy login

    Jnebembap January 26th, 2023 at 06:26 am回复
  52. Amvtpsype

    online pharmacy reviews for hydrocodone cvs pharmacy store 7164 safeway online pharmacy

    Amvtpsype January 26th, 2023 at 05:39 pm回复
  53. KenClelm

    viagra 1000mg price sildenafil uk best sildenafil in india

    KenClelm January 26th, 2023 at 07:03 pm回复
  54. Wmglembap

    buy generic viagra online europe viagra paypal sildenafil 20 mg without a prescription

    Wmglembap January 27th, 2023 at 06:37 am回复
  55. Jmeuembap

    viagra super active canada viagra 250 mg viagra singapore price

    Jmeuembap January 27th, 2023 at 01:44 pm回复
  56. gybrinc

    whats clomid used for Surgical options are rarely needed, although patients sometimes complain of haloes or colored rings at night, he says

    gybrinc January 27th, 2023 at 04:49 pm回复
  57. Ehdsketa

    viagra soft tabs 50mg viagra soft 100mg australia viagra

    Ehdsketa January 27th, 2023 at 05:56 pm回复
  58. Qnwrsketa

    best price on generic cialis wallmart cialis cialis and viagra together

    Qnwrsketa January 28th, 2023 at 05:14 am回复
  59. Arraply

    The Canadian Journal of Psychiatry La Revue canadienne de psychiatrie tadalafil generic vs cialis

    Arraply January 28th, 2023 at 05:42 am回复
  60. Tmrbsketa

    cialis mexico tadalafil buy thuoc tadalafil 20 mg

    Tmrbsketa January 28th, 2023 at 06:28 am回复
  61. Bymndassy

    If gastric irritation occurs, Doxyval 20 may be given with food or milk cialis online purchase In patients with diabetes, an analysis of 9 studies with over 9, 000 patients with diabetes reported that the patients randomized to statin therapy had a 0

    Bymndassy January 28th, 2023 at 08:48 am回复
  62. Amrbpsype

    sildenafil 20 mg online canada viagra nz over the counter viagra soft 100mg

    Amrbpsype January 28th, 2023 at 12:19 pm回复
  63. KnrClelm

    cheapest tadalafil 32 order cialis online no prescription reviews cialis efectos secundarios

    KnrClelm January 28th, 2023 at 05:04 pm回复
  64. Wdblembap

    tadalafil walgreens difference between tadalafil and cialis cialis online without perscription

    Wdblembap January 29th, 2023 at 05:42 am回复
  65. Jdnvembap

    cipla tadalafil review cheap original cialis canada cialis online

    Jdnvembap January 29th, 2023 at 12:52 pm回复
  66. Qjersketa

    cialis tadalafil 10mg 20 mg cialis cialis memes

    Qjersketa January 29th, 2023 at 03:30 pm回复
  67. Thwsketa

    buy cialis via pay pal cialis vs viagra vs levitra online doctor cialis

    Thwsketa January 29th, 2023 at 04:43 pm回复
  68. Ehdsketa

    viagra shop generic viagra soft tabs 100mg how to get a prescription for viagra

    Ehdsketa January 29th, 2023 at 07:20 pm回复
  69. Amrbpsype

    buy real viagra online genuine viagra for sale 30 mg sildenafil

    Amrbpsype January 30th, 2023 at 12:48 pm回复
  70. Unloara

    mobic rogaine foam for facial hair He said Гў This is a huge opportunity for East Anglia generic cialis from india

    Unloara January 30th, 2023 at 04:03 pm回复
  71. Wdblembap

    spierx tadalafil cheap cialis overnight cialis no prescription overnight

    Wdblembap January 31st, 2023 at 03:24 am回复
取消回复

说点什么?

© 2023 烈性果汁 . 京ICP备2022032198号